如何停止关闭cmd窗口

时间:2018-08-08 15:44:55

标签: c# wpf cmd

我在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();

我也尝试过:

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();

但是这里什么也没有发生。一个窗口仅出现一秒钟。 如何停止关闭窗口?为什么“ WaitForExit”不这样做?

1 个答案:

答案 0 :(得分:1)

尝试运行:

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对您不起作用,因为PsExec64.exe根本不等待用户输入。它以命令作为参数>>解析并运行>>退出过程。因此从技术上讲,您的“代码”确实等待PsExec64.exe退出然后继续。