1
votes

I'm trying to run a remote batch file - already located on the remote machine - using PsExec, called via Process in C#. I've confirmed that all required files already exist, but believe I may have a problem with my syntax, as the redirected output indicates that it can't find the file specified.

The machine against which PsExec runs is dynamic, which is the myArray[0].MachineName value (this pulls in without issue).

wsStopProcess.StartInfo.FileName = @"C:\Windows\system32\PsExec.exe";
wsStopProcess.StartInfo.Arguments = @" \\" + myArray[0].MachineName + @"D:\stopprofile.bat";

wsStopProcess.StartInfo.UseShellExecute = false;
wsStopProcess.StartInfo.CreateNoWindow = true;
wsStopProcess.StartInfo.RedirectStandardOutput = true;
wsStopProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

wsStopProcess.Start(); 

Any ideas on what appears to be formatted incorrectly? I'm guessing it's too many backslashes (or not enough!) somewhere.

2

2 Answers

0
votes

I think the main problem is you do not have a space between the two arguments.

Try this:

wsStopProcess.StartInfo.Arguments = @"\\" + myArray[0].MachineName + @" D:\stopprofile.bat";

I would also warn you that I could not get psexec to work 100%, despite trying many different things.

-1
votes

Try this:

wsStopProcess.StartInfo.Arguments = @"\\" + myArray[0].MachineName + @" D$\stopprofile.bat";

So instead of using : try $ sign. Also setting breakpoint on the above line while debugging will help you to see the exact path.