We help IT Professionals succeed at work.
Get Started

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

FSMB asked
Last Modified: 2012-05-09

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
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE