need tool PsExec to run below code,no need install,put PsExec.exe under folder bin。
download link:http://technet.microsoft.com/en-us/sysinternals/bb897553
Process remoteProcess = null;
fileName ="PsExec.exe"; commandLine = @"\\172.25.188.xx cmd /c netstat -an";//remote ip which you must have administrator permission try { remoteProcess = new Process(); remoteProcess.StartInfo.UseShellExecute = false; remoteProcess.StartInfo.RedirectStandardOutput = true; remoteProcess.StartInfo.RedirectStandardInput = true; remoteProcess.StartInfo.RedirectStandardError = true; if (!string.IsNullOrWhiteSpace(fileName)) { remoteProcess.StartInfo.FileName = fileName; } remoteProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; remoteProcess.StartInfo.Arguments = commandLine; remoteProcess.Start();
StreamReader myStreamReader = remoteProcess.StandardOutput; result = myStreamReader.ReadToEnd();//no dead lock ,but only part of output //result = remoteProcess.StandardOutput.ReadToEnd(); //dead lock happens here remoteProcess.WaitForExit(); }
Above is part of my code, I can't get the whole output,please see the comment inline.
Thanks.