简体   繁体   English

如何停止关闭cmd窗口

[英]How to stop the cmd window from closing

I run PsExec in a WPF application, but after execution, the window closes. 我在WPF应用程序中运行PsExec,但是执行后,窗口关闭。

Process process = new Process();
process.StartInfo.FileName = @"C:\Windows\SysWoW64\PsExec64.exe";
process.StartInfo.Arguments = String.Format(@"\\{0} ipconfig", TextBox_PCin.Text);
process.Start();
process.WaitForExit();

I also tried: 我也尝试过:

Process process = new Process();
process.StartInfo.FileName = @"C:\Windows\SysWoW64\PsExec64.exe";
process.StartInfo.Arguments = String.Format(@" \K \\{0} ipconfig", TextBox_PCin.Text);
process.Start();
process.WaitForExit();

but nothing happens here. 但这里什么也没有发生。 A window appears only for a second. 一个窗口仅出现一秒钟。 How can I stop the window from closing? 如何停止关闭窗口? Why doesn't "WaitForExit" do it? 为什么“ WaitForExit”不这样做?

Try running: 尝试运行:

Process process = new Process();
process.StartInfo.FileName = @"C:\Windows\System32\cmd.exe";
process.StartInfo.Arguments = String.Format(@"/k C:\Windows\SysWoW64\PsExec64.exe \\{0} ipconfig", TextBox_PCin.Text);
process.Start();
process.WaitForExit();

WaitForExit did not work for you because PsExec64.exe does not wait for user input at all. WaitForExit对您不起作用,因为PsExec64.exe根本不等待用户输入。 It take commands as an argument >> parse & run it >> exit process. 它以命令作为参数>>解析并运行>>退出过程。 So technically your "code" did wait for PsExec64.exe to exit and then continued. 因此,从技术上讲,您的“代码”确实等待PsExec64.exe退出然后继续。

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

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