在 C# 中获取 PsExec.exe 的进程 ID 需要帮助吗?
我使用下面的代码来调用 PsExec.exe,它在两个服务器中调用我的控制台应用程序,我无法获取被调用进程(我的控制台应用程序)的 ProcessId。
process.StandardOutput.ReadToEnd());只给我服务器名称而不是完整的内容。
您能帮我获取远程服务器上 PsExec.exe 生成的进程 ID 吗?
Process process = new Process();
ProcessStartInfo psi = new ProcessStartInfo(@"PsExec.exe");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.WindowStyle = ProcessWindowStyle.Minimized;
psi.CreateNoWindow = true;
psi.Arguments = @"-i -u Username -p xxxxxx \\server1,server2 C:\data\GridWorker\GridWorker.exe 100000";
process.StartInfo = psi;
process.Start();
Console.WriteLine(process.StandardOutput.ReadToEnd());
I am using the below code to invoke PsExec.exe which invokes my console application in two servers, I am not able to grab the ProcessId of the invoked processes (my console apps).
process.StandardOutput.ReadToEnd()); is only giving me the servernames but not the complete content.
Can you please help me to get the process id's generated by PsExec.exe on the remote servers ??
Process process = new Process();
ProcessStartInfo psi = new ProcessStartInfo(@"PsExec.exe");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.WindowStyle = ProcessWindowStyle.Minimized;
psi.CreateNoWindow = true;
psi.Arguments = @"-i -u Username -p xxxxxx \\server1,server2 C:\data\GridWorker\GridWorker.exe 100000";
process.StartInfo = psi;
process.Start();
Console.WriteLine(process.StandardOutput.ReadToEnd());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将
-d
参数添加到 PsExec 命令行。这应该正确地将进程 ID 返回到 StandardError。
示例:
输出:
Try adding the
-d
parameter to the PsExec commandline.This should correctly return the Process ID to StandardError.
The example:
Output:
我不认为你可以让 PsExec 以你想要的方式返回 pid。
但是,您可以做的是将自己的应用程序启动器包装器编写为控制台应用程序,并让它返回 pid。然后,您可以让 PsExec 始终通过调用此“AppStarter”来启动应用程序,从而返回您的 pid。
大致如下:
[这是一个粗略且准备好的示例,没有异常处理等 - 只是作为说明]
上面的代码现在变得像一样
I don't think you can get PsExec to return the pid in the way you want.
However, what you can do is write your own application starter wrapper as a console application, and have this return the pid. You can then have PsExec always start applications by calling this "AppStarter", thus returning your pid.
Something along the lines of:
[this is a rough and ready example, with no exception handling, etc - just as an illustration]
Your code above now becomes somthing like
到目前为止,我理解了最初的问题,任务是获取远程计算机上远程启动的进程的 PID。这是真的吗?在这种情况下,所有答案都没有真正的帮助。
您必须为每台远程计算机创建 WMI 查询,以获取已启动的进程。这可以使用“Win32_ProcessStartTrace”类来完成。
如果您需要更多帮助,请告诉我。
br--马布拉
So far I understodd the original question, the task was to get the PID of the remoetely started processes on the remote machines. Is this true? In this case, none of the answers are really helpful.
You must create WMI queries for each of you remote computers, to fetch the started processes. This can be done using the "Win32_ProcessStartTrace" classes.
If you need more help, let me know.
br--mabra