I need execute a program in the remote computer, so I created a service in order to call psexec (it’s crucial using the service). However, this service cannot call psexec.
Following the code:
String cmd = "", arguments = "";
cmd = @"C:\PsTools\psexec.exe";
arguments = @"\\remoteComputer -u "user" -p "password" "C:\program.exe"";
Process process = new Process();
process.StartInfo.FileName = cmd;
process.StartInfo.Arguments = arguments;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
result = process.StandardOutput.ReadToEnd();
sError = process.StandardError.ReadToEnd();
result += "Program has finished its execution";
Do anyone know why the service cannot call the psexec?
I had issues with psexec hanging too when running a batch file remotely. How about WMI? This worked for me when running something on a remote computer; it works for *.bat and *.exe too. You might need to click Project>Add Reference and choose “System.Management” on the .NET tab–the reference wasn’t there in VS 2010 until I manually added it.