0
votes

I am experimenting with PsExec and I am trying to run a batch file on a remote host from a local PC on the same LAN. The batch file has been tested on the local PC and works fine. I managed to connect to the remote host via PsExec using the below commands.

PsExec -u Username -p Password \\Remote_Host_IP C:\Path_to_batch_file\Batch.bat

I am getting this error:-

PsExec could not start C:\Path_to_batch_file\Batch.bat on Remote_Host_IP: The system cannot find the file specified.

This is probably occurring since it is searching for the file on the remote host while the file is located on the local PC thus not finding the file. I do not want to make any manual intervention on the remote host.

After trying hard to find the correct commands on the net I cannot solve this issue.

3
It's a kind of bad workaround but try PsExec -u Username -p Password \\Remote_Host_IP \\%computername%\C$\Path_to_batch_file\Batch.bat The computername variable will be evaluated on your local machine but the remote user has to have the rights to read the file on your local machine. (In this case the admin share). In any other case you have to copy the file to the remote host (or embed it in the PsExec statement)Clijsters
In fact I solved the issue by copying the required files to the remote machine using robocopy.user2307236

3 Answers

1
votes

If you want you can try this:

PsExec.exe @pc_list.txt >>pc_log.txt -c D:\PC\pc.bat

Where:

pc_list.txt is a list of all your PC in your network
       pc_log.txt is a log
       D:\PC\pc.bat is the path where your script is

You can schedule it from a server that has access on all your network with task scheduler

0
votes

Try this.

Psexec \\remotehost -u username -p password -c local_path\file.bat
-1
votes

Run it as:

PsExec \Remote_Host_IP -u Username -p Password cmd/c "C:\Path_to_batch_file\Batch.bat"

This should fix it