How to programmatically open control panel?

自古美人都是妖i 提交于 2019-12-21 17:49:21

问题


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?


回答1:


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)




回答2:


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);



回答3:


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

            **Process.Start(System.Environment.SystemDirectory + @"\appwiz.cpl");**



回答4:


just use this....

ProcessStartInfo startInfo = new ProcessStartInfo("appwiz.cpl");
startInfo.UseShellExecute = true;
Process.Start(startInfo);



回答5:


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); }
    }


来源:https://stackoverflow.com/questions/503636/how-to-programmatically-open-control-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!