In the program, I want to use PsExec to execute exe file in remote desktop.
The exe file will be executed right after the restart process. Unfortunately,I get the error as below and the exit code 2.
PsExec could not start C:\Test\try.exe on <remote desktop>
The system cannot find the file specified.
But if I log in to the remote desktop before the execution, the exe file can runs successfully.
C:\Test\try.exe exited on <remote desktop> with error code 0.
Looks like I need to log in to the remote desktop first before I want to execute the file. Is there any suggestion if I want the exe file executed right after the restart process?
What I have tried:
public Process ExecuteTest(string remote, string Path)
{
return new Process
{
StartInfo =
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
FileName = "PsExec64.exe",
Arguments = @"\\" + remote + " -accepteula -u Administrator -p P@ssw0rd -h -s -i 2 " + Path
}
};
}
....
Process pro = ExecuteTest(remote, @"C:\Test\try.exe");
pro.Start();
string error =pro.StandardError.ReadToEnd();
pro.WaitForExit();
Console.Writeline(error);