2013-07-06 20 views
0

我的代码:C#PSEXEC获取进程列表:名称,路径

Process p = new Process(); 
p.StartInfo.UseShellExecute = false; 
p.StartInfo.RedirectStandardOutput = true; 
p.StartInfo.RedirectStandardError = true; 
p.StartInfo.RedirectStandardInput = true; 
p.StartInfo.FileName = Environment.CurrentDirectory + @"\PsExec\PsExec.exe"; 
p.StartInfo.Arguments = @"\\server-0 cmd /c wmic process get description,executablepath"; 
p.Start(); 
string output = p.StandardOutput.ReadToEnd(); 
string errormessage = p.StandardError.ReadToEnd(); 
p.WaitForExit(); 

控制台窗口不会关闭本身。当我手动关闭它时,我看到(在输出中):

Description    ExecutablePath            

我没有看到任何其他行!但是,如果我写相同的控制台:

psexec \\server-0 cmd /c wmic process get description,executablepath 

我看到:

Description    ExecutablePath 
System Idle Process 
System 
smss.exe 
csrss.exe    C:\Windows\system32\csrss.exe 
wininit.exe    C:\Windows\system32\wininit.exe 
csrss.exe    C:\Windows\system32\csrss.exe 
... 

我尝试了一些想法,如:Thread.Sleep(...),每行阅读,-accepteulaEnableRaisingEvents/OutputDataReceived(它不叫) ,-d标志(无输出),UseShellExecute=true(工程,但我无法隐藏控制台窗口)...

为什么我只收到第一行(在上面的C#代码中)?我应该改变什么来接收我在控制台中看到的相同内容?

对不起,英语不好。感谢您的回答。

+0

你有问题吗? –

+0

@MichaelBray是的,我需要帮助 – Dmitry

+0

我的观点是,因为很明显你的英语不是很好,所以你*没有*问过一个问题。如果您希望收到答案,请询问关于您的代码的具体问题。事实上,你所说的只是“请修复它”。 –

回答

-1

使用委托。收到的输出上升事件并捕获数据。我做了同样的