简体   繁体   English

链接到C#中的控制面板(运行播发的程序和Configuration Manager)

[英]Linking to control panel in C# (Run advertised programs and Configuration Manager)

I am trying to link to the control panel from within a C# application. 我正在尝试从C#应用程序链接到控制面板。 I am coding in visual studio and trying to find a way to make a link to those two areas in the control panel. 我正在Visual Studio中进行编码,并试图找到一种方法来链接到控制面板中的这两个区域。

I have been using System.Diagnostics.Process.Start() but I can't seem to find a way to actually link my way to anywhere inside of the control panel except for a select few places where applets are already defined, such as printers and color. 我一直在使用System.Diagnostics.Process.Start(),但似乎无法找到一种方法将我的方法实际链接到控制面板内的任何位置,除了已经定义了小程序的少数几个位置(例如打印机)和颜色。

Please let me know if you have any idea how to come upon this solution. 如果您有任何想法如何提出此解决方案,请告诉我。

this works for me: 这对我有用:

var cplPath = System.IO.Path.Combine(Environment.SystemDirectory, "control.exe");
System.Diagnostics.Process.Start(cplPath, "/name Microsoft.ProgramsAndFeatures");

You can also specify a page of the control panelitem. 您还可以指定控制面板项目的页面。 Check out Executing Control Panel Items and Canonical Names of Control Panel Items 签出执行控制面板项目控制面板项目的 规范名称

If you just want to launch a control panel window the command is 如果您只想启动控制面板窗口,则命令为

System.Diagnostics.Process.Start("control");

If you want to launch the individual items in the control panel, you need to know it's filename (check the Windows\\System32 or Windows\\SYSWOW64 for the files, they end in .cpl ) you can then launch it like this. 如果要在控制面板中启动各个项目,则需要知道其文件名(检查Windows\\System32Windows\\SYSWOW64中的文件,它们以.cpl结尾),然后可以像这样启动它。

System.Diagnostics.Process.Start("control", "powercfg.cpl");

If you type "Start Control" or "Control" into Command Prompt it will open Control Panel. 如果在命令提示符下键入“开始控制”或“控制”,它将打开控制面板。

Therefore I would run a Process and run it. 因此,我将运行一个流程并运行它。 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); }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM