如何在 Process.Start() 中通过 cmd.exe 运行 cmd.exe 和许多开关
与上一个问题类似,我有时在 cmd.exe 上运行此命令:
Rundll32 Printui.dll,PrintUIEntry /ia /K /q /m "SHARP MX-5500N PS" /h "Windows NT x86" /v 3 /f sn0hwenu.inf
如果我想通过 Process.Start() 运行此命令,一切都取决于 PrintUIEntry 文件名和其余参数吗?我是否需要在上述字符串的前面连接 cmd.exe (无论如何我假设是),如果是这种情况,那么就是文件名和其余参数。这里有什么经验法则吗?
谢谢
Similar to a previous question, I sometimes run this command on cmd.exe:
Rundll32 Printui.dll,PrintUIEntry /ia /K /q /m "SHARP MX-5500N PS" /h "Windows NT x86" /v 3 /f sn0hwenu.inf
If I want to run this via Process.Start(), is everything up to PrintUIEntry the filename and the rest arguments? Do I need to concat cmd.exe at the front of the above string (I am assuming yes anyway), and if that is the case, then is that the file name and the rest arguments. Is there any rule of thumb here?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文件名应为
Rundll32.exe
。 Printui.dll 等是参数。您不需要 cmd.exe,因为 rundll32 是它自己的程序。The filename should be
Rundll32.exe
. Printui.dll,etc are arguments. You do not needcmd.exe
, since rundll32 is its own program.您可以使用 ProcessStartInfo 指定要运行的文件 (rundll32),并使用 Arguments 属性指定要使用的参数。它不是一个数组,而是一个字符串。
startInfo.Arguments = "/x /y /z";
您不需要 cmd.exe,因为您正在启动一个进程,该进程将是 rundll32,不需要 cmd 来托管它。
请注意,您可能需要将参数括在引号中(看起来您已经在这样做了)。例如,如果您提供路径 c:\Program Files...,则需要将其用引号括起来,否则在尝试运行该进程时会出现错误。
另请记住,单独指定 rundll32.exe 可能不会工作。我不确定 process.Start 是否使用 PATH 环境变量来解析该文件,因此您可能需要提供 rundll32.exe 的完整路径
You can use ProcessStartInfo to specify the file to run (rundll32) and the Arguments property to specify the arguments to use. It is not an array, but a string.
startInfo.Arguments = "/x /y /z";
You don't need cmd.exe because you're starting a process which is going to be rundll32 which doesn't require cmd to host it.
Note that you may need to wrap arguments in quotes (which it looks like you're already doing). For example, if you're giving a path c:\Program Files... you will need to wrap that in quotes or you'll get errors when trying to run the process
Also keep in mind that specifying rundll32.exe alone might not work. I'm not sure if process.Start uses PATH environment variables to resolve the file so you might need to give the full path to rundll32.exe