EDN Admin
Well-known member
Hi all!
I start a process to run PsExec like this:
<div style="color:Black;background-color:White; <pre>
<span style="color:Green; // Create a process for execute psexec
ProcessStartInfo processInfo = <span style="color:Blue; new ProcessStartInfo();
processInfo.FileName = Path.Combine(<span style="color:Blue; this.ToolsPath, <span style="color:#A31515; "psexec.exe");
processInfo.Arguments = <span style="color:#A31515; @"\" + (<span style="color:Blue; new Uri(destination)).Host + <span style="color:#A31515; " -u " + domain + <span style="color:#A31515; @"" + login + <span style="color:#A31515; " -p " + password + <span style="color:#A31515; @" -accepteula -c -f " + <span style="color:Blue; this.Executable + <span style="color:#A31515; " " + <span style="color:Blue; this.CommandLine;
processInfo.RedirectStandardOutput = <span style="color:Blue; true;
processInfo.UseShellExecute = <span style="color:Blue; false;
processInfo.RedirectStandardError = <span style="color:Blue; true;
processInfo.WindowStyle = ProcessWindowStyle.Hidden;
processInfo.CreateNoWindow = <span style="color:Blue; true;
processInfo.ErrorDialog = <span style="color:Blue; false;
<span style="color:Green; // Start the process
<span style="color:Blue; using(process = Process.Start(processInfo))
{
<span style="color:Green; // Microsoft say : Do not wait for the child process to exit before reading to the end of its redirected stream.
<span style="color:Green; // Read the output stream first and then wait.
process.ErrorDataReceived += (sender, errorLine) => { <span style="color:Blue; if(!String.IsNullOrEmpty(errorLine.Data)) LogManager.TraceError(errorLine.Data); };
process.OutputDataReceived += (sender, outputLine) => { <span style="color:Blue; if(!String.IsNullOrEmpty(outputLine.Data)) LogManager.TraceVerbose(outputLine.Data); };
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit(120000);
process.CancelErrorRead();
process.CancelOutputRead();
<span style="color:Green; // If process is not terminated
<span style="color:Blue; if(!process.HasExited)
{
process.Kill();
<span style="color:Green; // Failed on timeout
}
<span style="color:Blue; else
{
<span style="color:Blue; if(process.ExitCode == 0)
{
...
}
}
}
[/code]
<br/>
PsExec run normally but process.WaitForexit(120000) dont exit before the timeout and the standard output has only the first 3 lines of output of PsExec.
If i set redirectStandardOutput to false there is no matter.
Could you help me?
Thanks
View the full article
I start a process to run PsExec like this:
<div style="color:Black;background-color:White; <pre>
<span style="color:Green; // Create a process for execute psexec
ProcessStartInfo processInfo = <span style="color:Blue; new ProcessStartInfo();
processInfo.FileName = Path.Combine(<span style="color:Blue; this.ToolsPath, <span style="color:#A31515; "psexec.exe");
processInfo.Arguments = <span style="color:#A31515; @"\" + (<span style="color:Blue; new Uri(destination)).Host + <span style="color:#A31515; " -u " + domain + <span style="color:#A31515; @"" + login + <span style="color:#A31515; " -p " + password + <span style="color:#A31515; @" -accepteula -c -f " + <span style="color:Blue; this.Executable + <span style="color:#A31515; " " + <span style="color:Blue; this.CommandLine;
processInfo.RedirectStandardOutput = <span style="color:Blue; true;
processInfo.UseShellExecute = <span style="color:Blue; false;
processInfo.RedirectStandardError = <span style="color:Blue; true;
processInfo.WindowStyle = ProcessWindowStyle.Hidden;
processInfo.CreateNoWindow = <span style="color:Blue; true;
processInfo.ErrorDialog = <span style="color:Blue; false;
<span style="color:Green; // Start the process
<span style="color:Blue; using(process = Process.Start(processInfo))
{
<span style="color:Green; // Microsoft say : Do not wait for the child process to exit before reading to the end of its redirected stream.
<span style="color:Green; // Read the output stream first and then wait.
process.ErrorDataReceived += (sender, errorLine) => { <span style="color:Blue; if(!String.IsNullOrEmpty(errorLine.Data)) LogManager.TraceError(errorLine.Data); };
process.OutputDataReceived += (sender, outputLine) => { <span style="color:Blue; if(!String.IsNullOrEmpty(outputLine.Data)) LogManager.TraceVerbose(outputLine.Data); };
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit(120000);
process.CancelErrorRead();
process.CancelOutputRead();
<span style="color:Green; // If process is not terminated
<span style="color:Blue; if(!process.HasExited)
{
process.Kill();
<span style="color:Green; // Failed on timeout
}
<span style="color:Blue; else
{
<span style="color:Blue; if(process.ExitCode == 0)
{
...
}
}
}
[/code]
<br/>
PsExec run normally but process.WaitForexit(120000) dont exit before the timeout and the standard output has only the first 3 lines of output of PsExec.
If i set redirectStandardOutput to false there is no matter.
Could you help me?
Thanks
View the full article