0

I'm trying to make a batch file to run a script on remote server. If I enter the commands below in the cmd prompt seperately it works fine but it seems to hang after I enter the psexec commands. It only continues the rest of the batch file when I exit the psexec remote connection. The rest of the commands are run on my local computer(which I don't want). Anyone have any ideas or suggestions?

psexec \\ServName -u DOMAIN\UserName -p password cmd.exe
pause
cd c:\Users\UserName
pause
cscript \\NetworkName\filepath\blankTest.vbs
giacmeister
  • 35
  • 1
  • 2
  • 7

2 Answers2

0

Personnaly if I want to start a background process in a batch I use this :
start /B cmd /C "mycommand" which in your case should give :
start /B cmd /C "psexec \\ServName -u DOMAIN\UserName -p password cmd.exe"

Hybris95
  • 2,286
  • 2
  • 16
  • 33
  • Thanks for the input, however, the batch still hangs after the first command. To be more specific, when it runs the psexec command it runs perfectly and rdps to the remote server. After that I want it to run the next few lines of commands(pause; cd c:\Users...) but it just stays at the command prompt of the remote server. Only when I exit the rdp session in the command prompt it runs the next few lines of commands. @hybris95 – giacmeister Jun 03 '14 at 14:46
  • Considering this answer http://stackoverflow.com/questions/1449188/running-windows-batch-file-commands-asynchronously using `start "yourcommand"` should work. – Hybris95 Jun 03 '14 at 14:52
  • Oh I get it, you wish those commands to be executed remotely then try this out : `psexec \\ServName -u DOMAIN\UserName -p password cmd.exe /C "pause ; cd c:\Users\UserName ; pause ; cscript \\NetworkName\filepath\blankTest.vbs"` – Hybris95 Jun 03 '14 at 14:56
0

You can bundle the commands into one batch file and then execute that using one line:

psexec \\ServName -u DOMAIN\UserName -p password cmd.exe -c mybatchfile.bat

That will cause the file to be copied to the remote machine first. Alternatively if you have problems with that, copy the file first, then execute it; note the different parameter, /c vs -c:

copy mybatchfile.bat \\ServName\Admin$
psexec \\ServName -u DOMAIN\UserName -p password cmd.exe /c mybatchfile.bat
Geoff
  • 8,551
  • 1
  • 43
  • 50
  • This worked. I used the latter of the two options. I had to create a separate directory folder within the server for the batch file before copying it over for organizational purposes. @geoff – giacmeister Jun 03 '14 at 19:25