My code:
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();
The console window does not close itself. When I close it manually, I see (in output):
Description ExecutablePath
I don't see any other line! But if I write the same in the console:
psexec \\server-0 cmd /c wmic process get description,executablepath
I see:
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
...
I tried some ideas like: Thread.Sleep(...)
, per line reading, -accepteula
, EnableRaisingEvents
/ OutputDataReceived
(it does not call), -d flag (no output), UseShellExecute=true
(works, but I couldn't hide the console window)...
Why do I receive only the first row (in the C# code above)? What should I change to receive the same content I see in the console?
Sorry for the bad English. Thanks for your answers.