0

I need to run a command "control bthprops.cpl" in a C# program. This command brings up Bluetooth Settings control panel window. I tried running it using Process.Start() but the bluetooth window doesn't show up. I also tried writing a BAT file to the disk and executing it though my program, but still has the same problem. Is there any way to accomplish this?

//Dump BAT File and execute it
string path = System.IO.Directory.GetCurrentDirectory()+"startBT.bat";
string[] content = {"control bthprops.cpl"};
System.IO.File.WriteAllLines(path, content);

//Execute BAT file
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = path;
p.Start();
4

2 回答 2

3

不需要带BAT文件,这一行应该打开指定的控制面板;

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

因为我没有前面提到的 bthprops.cpl;至少这适用于 W7(打开桌面设置)

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

如果您的控制面板有标签,您甚至可以选择要打开的标签;

System.Diagnostics.Process.Start("control", "bthprops.cpl,,2");
于 2013-10-03T21:00:19.970 回答
1

提供完整路径并启动它,例如:

var path = Path.Combine(Environment.SystemDirectory, "bthprops.cpl");
if (File.Exists(path))
{
   Process.Start(path);
}
于 2013-10-03T21:00:38.100 回答