We help IT Professionals succeed at work.

How do I get a VBScript or BATCH that calls a VBScript to fire off on a remote machine using PSEXEC?

FSMB used Ask the Experts™

I have been succesful at using PSEXEC to fire off a VBScript on a remote server, but I am running into problems with a different script executing on another Domain PC.

Here is the BATCH file that works perfectly:
LogMerge.bat: (The .VBS was already on the destination Host as I know the limitation of using PSEXEC with cscript)

@echo off
echo Merging logs, please wait...
start /wait psexec.exe \\XXnameXX -c -f cscript.exe "\\XXnameXX\d$\department\Support\LogMerge.vbs"

Open in new window

Now, I am trying to run a different script which will be copied too and fired off on a list of remote domain PC's on our network.  This is what it looks like:

@echo off

echo Uninstalling Timeclock Pro version 5.6, please wait...

For /F %%a in (c:\PsTools\tcWork\Host5.txt) do (
xcopy /d/y/s "C:\PsTools\tcWork\RemShort.vbs" "\\%%a\c$\temp\"
rem xcopy /d/y/s "C:\PsTools\tcWork\RemShort.bat" "\\%%a\c$\temp\"
rem start /wait psexec.exe @Host5.txt -s -c -f -w c:\temp tcRemove2.bat
rem start /wait psexec.exe @Host5.txt -s -c -f -w c:\temp tcCleanup.bat
rem start /wait psexec.exe @Host5.txt -s -c -f -w c:\temp RemShort.bat
start /wait psexec.exe @Host5.txt -s -c -f cscript.exe c:\temp\RemShort.vbs

rem for /F %%a in (c:\PsTools\tcWork\Host5.txt) do (
rem xcopy /d/y/s "\\%%a\c$\tclogs\*.log" "\\XXnameXX\d$\department\Support\logs\"
rem )


Open in new window

For testing purposes I REM'd all the lines that I know already work and do not want running while I'l troubleshooting the 'RemShort.vbs' script issue.  Using the above batch file, the process runs and I get that the process exited with error 0, which typically means it worked, but the thing is it didn't work.  It's supposed to remove a short cut from all user profile's Desktop.  If I run the script locally on the same host PC, it works like a charm.  For troubleshooting purposes, I added the above REM'd lines that instead of trying to call the VBS directly using cscript, I copy a RemShort.BAT over and then call the batch so it will execute the cscript command locally to that PC.  I get the same 'exited with error 0' display and nothing happens.  I can run the same batch locally by clicking on it and it does what it's supposed to do.  I can't figure out why this particular script just does not want to be run remotely, when the 1st script I listed works perfectly fine remotely.

Let me know if ya'll need to see the scripts themselves.  I was not sure if the actual script code was relevant.  They both work like a charm only the  RemShort.vbs has issues with remote execution.

Thanks in advance for your help,
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Yes, it would help to see the RemShort.vbs. I suppose the RemShort.bat did nothing more than calling cscript with RemShort.vbs - if not, please show us that script, too.

Why are you using all those switches for psexec?
-s       runs in system account    - maybe that is the issue, though unlikely
-c       copy file to execute   - cscript.exe is always available on the other side
-f        force overwrite of the file to execute   - an existing cscript will be replaced
I would try psexec without those switches, but with -i and an administrative user account (-u and -p).
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Could you please add a short comment which of the changes I suggested helped? Future readers might have the same issue ...


Thanks for putting my mind on the right track.  I got the BATCH solution to work by using the -u -p switches and an admin user.  For some reason I could have swore I tried that.  I must have been typing something wrong.

As for the cscript way, I had tried every possible combination of switches to try and get it to work, even tried without the switches, and also with an admin account and could not get it to work.  PSEXEC with the batch file worked though with your guidance, so I'm happy.


I was actually typing up the comment as you were posting for me to add a comment :-)

Just to clarify my previous comment, the PSEXEC command that worked for me in this case was:

start /wait psexec.exe @Host5.txt -u AccountName -p Password -c -f -w c:\temp RemShort.bat

Then the batch file called the VBS local to the remote machine with csript. -> cscript C:\Temp\RemShort.vbs

Thanks again for your help.