Search code examples
c#wpfwindowscontrolpanel

Programmatically open 'Set Associations' in WPF application?


I want my user to be able to press a button and start a given control panel item, such as the Set Associations window. Must work for any Windows version, but the path would lead here:

Control Panel\All Control Panel Items\Default Programs\Set Associations

I am using C#/WPF to do this, but can't find information on how to do this for a specific Control Panel page like above and that works for all Windows versions.

Thanks!

UPDATE

The following works to access a page:

System.Diagnostics.Process.Start("C:\\Windows\\System32\\control.exe", "/name Microsoft.DefaultPrograms /page pageFileAssoc");

Solution

  • You should use Process class to run a canonical address of the control panel item you want to show. You can show control panel window by executing c:\windows\system32\control.exe then you should add the canonical name as parameters for this process.

    public static void Main()
        {
            Process myProcess = new Process();
    
            try
            {
                myProcess.StartInfo.FileName = "c:\\windows\\system32\\control.exe";
                myProcess.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    

    see here for more info on canonical names.