How to programmatically open control panel?
Asked Answered
A

5

7

How do I open a custom control panel programmatically, like custom.cpl? Specifically, how do I open a 64-bit cpl when running as 32-bit application?

Acrefoot answered 2/2, 2009 at 15:40 Comment(1)
I decided for community wiki as I basically answered the question myself, but only for 32-bit control panel.Acrefoot
C
6

Vista added support for canonical names so you don't have to hard code dll filenames and tab indexs

Example: WinExec("%systemroot%\system32\control.exe /name Microsoft.WindowsUpdate", SW_NORMAL);

(Names are always in english)

See MSDN for a list

XP/2000 supports "control.exe mouse" and a few other keywords, see the same MSDN page for a list (You can probably find some undocumented ones by running strings on control.exe)

Carrolcarroll answered 2/2, 2009 at 15:40 Comment(0)
D
5

just use this....

ProcessStartInfo startInfo = new ProcessStartInfo("appwiz.cpl");
startInfo.UseShellExecute = true;
Process.Start(startInfo);
Decennary answered 2/2, 2009 at 15:40 Comment(1)
Thanks, that UseShellExecute part was important. Updating an old .NET project to .NET 6 required this change for me, where it wasn't previously needed.Originative
A
5

Since I didn't find a good answer here on SO, here's the solution of my research:

  • Start a new application "control" that gets the name of the control panel as its first parameter:
::ShellExecute(m_hWnd, NULL, _T("control.exe"), _T("access.cpl"), NULL, SW_SHOW);
Acrefoot answered 2/2, 2009 at 15:40 Comment(0)
R
1

As i previously mentioned in another Question:

If you type "Start Control" or "Control" into Command Prompt it will open Control Panel.

Therefore just run a Process.

This Code (Bellow) worked perfectly for me:

public Form1()
{
     InitializeComponent();
}

    #region Variables
    Process p;
    #endregion Variables

    [...]

    void myMethod()
    {
            try
            {
                p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.UseShellExecute = false;
                p.Start();

                p.StandardInput.WriteLine("start control"); 
                p.StandardInput.Flush();
                p.StandardInput.Close();
                Console.WriteLine(p.StandardOutput.ReadToEnd());
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
    }
Radarman answered 2/2, 2009 at 15:40 Comment(0)
E
1

Step1 : Read System Directory from the machine. Step2 : Use Process to start ControlPanel

            **Process.Start(System.Environment.SystemDirectory + @"\appwiz.cpl");**
Eddyede answered 2/2, 2009 at 15:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.