为什么Process.Start(“cmd.exe”,进程);不行? [英] Why does Process.Start("cmd.exe", process); not work?
本文介绍了为什么Process.Start(“cmd.exe”,进程);不行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这样做:
Process.Start(control,/ name Microsoft.DevicesAndPrinters);
但这不:(它只是打开一个命令提示符。)
ProcessStartInfo info = new ProcessStartInfo(cmd.exe);
info.Arguments =control / name Microsoft.DevicesAndPrinters;
Process.Start(info);
为什么?
但是第二个应该工作。)
解决方案
这是因为 cmd.exe
需要一个 / K
切换来执行作为参数传递的进程。尝试下面的代码
ProcessStartInfo info = new ProcessStartInfo(cmd.exe);
info.Arguments =/ K control / name Microsoft.DevicesAndPrinters;
Process.Start(info);
编辑:已更改为 / K
如果在运行命令后要关闭 cmd.exe
,可以使用 / C
>
This works:
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);
Why?
(Yes, I know they're not identical. But the second one "should" work.)
解决方案
This is because cmd.exe
expects a /K
switch to execute a process passed as an argument. Try the code below
ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
info.Arguments = "/K control /name Microsoft.DevicesAndPrinters";
Process.Start(info);
EDIT: 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屋!
查看全文