从远程执行的.exe获取响应

时间:2013-06-28 14:19:56

标签: c# .net cmd remote-server psexec

我正在执行一个位于远程服务器上的.exe,但是PsExec似乎挂起并且本地服务没有退出。 .exe确实在服务器上成功运行,但是当它完成时我希望本地服务退出。

这是我的代码:

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.FileName = @"C:\Program Files (x86)\PSTools\PsExec.exe";
p.StartInfo.Arguments = @"\\<remote .exe path>";
p.Start();

//I have tried the following to exit the local service when a response is
//received but it still hangs.
//string output = p.StandardOutput.ReadToEnd();
//string errormessage = p.StandardError.ReadToEnd();
//p.WaitForExit();

远程服务完成后退出本地服务需要做什么?

2 个答案:

答案 0 :(得分:0)

你试过p.WaitForInputIdle();吗?

-------------更新

差异GUI /非GUI:How can I tell if a process has a graphical interface?

答案 1 :(得分:0)

您可以尝试使用-d选项运行psexec,建议用于非交互式应用程序。或者您可以在psexec上设置超时选项?

相关问题