Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
        }
    };
}


///restart desktop process
....
Process pro = ExecuteTest(remote, @"C:\Test\try.exe");
pro.Start(); 
string error =pro.StandardError.ReadToEnd();
pro.WaitForExit();
Console.Writeline(error);
Posted
Updated 9-Mar-22 23:34pm
v2

1 solution

Maybe you can use the alternative mentioned in this CodeProject article:
Running Programs on a Remote Machine with Web Services[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900