为什么的Process.Start(" CMD.EXE",流程);不行? [英] Why does Process.Start("cmd.exe", process); not work?
本文介绍了为什么的Process.Start(" CMD.EXE",流程);不行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
本作品:
Process.Start("control", "/name Microsoft.DevicesAndPrinters");
不过,这并不:(它只是打开一个命令提示符)
But this doesn't: (It just opens a command prompt.)
ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
info.Arguments = "control /name Microsoft.DevicesAndPrinters";
Process.Start(info);
为什么?
(是的,我知道他们是不相同的,但第二个应当的工作。)
(Yes, I know they're not identical. But the second one "should" work.)
推荐答案
这是因为CMD.EXE需要一个/ K开关来执行通过为实际参数的一个过程。尝试下面
This is because cmd.exe expects a /K switch to execute a process passed as an arguement. Try the code below
ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
info.Arguments = "/K control /name Microsoft.DevicesAndPrinters";
Process.Start(info);
编辑:更改为/ K以上。您可以使用/ C开关,如果你想的CMD.exe关闭后,已运行的命令。
Changed to /K above. You can use /C switch if you want CMD.exe to close after it has run the command.
这篇关于为什么的Process.Start(" CMD.EXE",流程);不行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文