Executing PsExec from a Batch File.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
s9kupusa
Posts: 2
Joined: 27 Nov 2012 13:28

Executing PsExec from a Batch File.

#1 Post by s9kupusa » 27 Nov 2012 13:45

Good Afternoon!

I am fairly new to windows batch processing and have the following question for everyone.

Requirement: Call a Batch file XYZ on Remote Server A from Server B

I was able to successfully call the Batch file on the remote server using PsExec directly from CMD but when I encapsulate the PsExec command into a separate batch file and execute it, the process executes fine but it does not execute the target batch file on Remote Server A

Script which I used directly on my local CMD that executed the DEV_CACHE_UPDT.bat successfully.

Code: Select all

------------------------------------------------------------------------------------------------------------------------
C:\TEST\PsExec.exe \\REMOTE-SERVER-A -u ABC -i -d cmd /c c:\MS\UPDT.bat
....
....
....
cmd started on REMOTE-SERVER-A with process ID 1234
-------------------------------------------------------------------------------------------------------------------------


I encapsulated the above script into a batch file by itself (TEST2.bat)

Code: Select all

@ECHO ON 
C:\TEST\PsExec.exe \\REMOTE-SERVER-A -u ABC -i -d cmd /c c:\MS\UPDT.bat

Called Test2.bat from CMD

Code: Select all

------------------------------------------------------------------------------------------------------------------------
C:\Batch\Test2.bat
...
...
...
...
cmd started on REMOTE-SERVER-A with process ID 6789
------------------------------------------------------------------------------------------------------------------------


The process runs fine but it does not execute the UPDT.bat in the REMOTE-SERVER-A

I am not sure why the script executes fine when applied directly on CMD but it does not pass the command to Remote Server A when PsExec is used in a Batch file.

Any ideas will be highly appreciated..

Thanks!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Executing PsExec from a Batch File.

#2 Post by foxidrive » 27 Nov 2012 15:51

Are you launching a cmd prompt elevated to administator and then launching the batch file?
Give it a go, as a test.

Do you get prompted for a password on the remote system?

s9kupusa
Posts: 2
Joined: 27 Nov 2012 13:28

Re: Executing PsExec from a Batch File.

#3 Post by s9kupusa » 27 Nov 2012 22:42

My Bet... I forgot to include the full folder path to the Batch file. When I compared the script used on the CMD vs. in the Batch file, the Batch file was missing a folder.

It should have been:

Code: Select all

C:\TEST\PsExec.exe \\REMOTE-SERVER-A -u ABC -i -d cmd /c c:\MS\Batch\UPDT.bat


The PsExec works fine now :)

Thanks!

Post Reply