I have a batch file, say A.bat On execution, this A.bat will create another batch file, say remote.bat
If I manually copy the remote.bat to the remote machine then it works 100% perfect. However, if I use it as a part of psExec in my A.bat then it does not work at all. However, my A.bat while executing says..
Connecting to ABCDEF machine
Starting PsExec Server on ABCDEF machine
Copying C:\remote.bat on ABCDEF machine
Started C:\remote.bat ABCDEF machine with Process Id XXXX
However, it looks to me that the remote.bat file is not executed at all.
What I have inside remote.bat is..
net use \\DIR1\DIR2 password /user:Administrator
XCOPY \\DIR1\DIR2\DIR3\DIR4\* c:\DIR3\DIR4\ /E
I do not see the DIR3\DIR4 getting created under C: of my remote machine at all. However, it works if I manually copy the remote.bat and execute it in my remote machine.
The command I use to call PsExec is
psexec \\MachineName -u Administrator -p pasword -d -c -f c:\remote.bat
Any advice? please?
The association of BAT files with CMD is in your local user profile. I'm not shure how the Shell handles it exactly, but calling psexec on a remote target won't invoke cmd to run your batch file.
Put cmd.exe /c in front of remote.bat like this instead :
psexec \\MachineName -u Administrator -p pasword -d -c -f cmd.exe /c c:\remote.bat
But you must get the file remote.bat across first. The whole thing would look like this :
net use \\MachineName\C$ password /user:Administrator
XCOPY remote.bat \\MachineName\C$\remote.bat
psexec \\MachineName -u Administrator -p pasword -d -c -f cmd.exe /c c:\remote.bat
net use /delete \\MachineName\C$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With