Sysinternals Homepage
Forum Home Forum Home > Sysinternals Utilities > PsTools
  New Posts New Posts RSS Feed: Psexec batch file
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Psexec batch file

 Post Reply Post Reply
Author
Message Reverse Sort Order
Karlchen View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 June 2005
Location: Germany
Online Status: Offline
Posts: 5121
Post Options Post Options   Quote Karlchen Quote  Post ReplyReply Direct Link To This Post Topic: Psexec batch file
    Posted: 20 November 2006 at 5:13pm
Glad to read this. Thanks for your feedback.

Karl
Back to Top
kahanlon View Drop Down
Newbie
Newbie


Joined: 19 November 2006
Online Status: Offline
Posts: 2
Post Options Post Options   Quote kahanlon Quote  Post ReplyReply Direct Link To This Post Posted: 19 November 2006 at 8:37pm

I never thought of calling another batch file, it worked like a charm with the psexec -c option.

Thank you
Keith

Back to Top
Karlchen View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 June 2005
Location: Germany
Online Status: Offline
Posts: 5121
Post Options Post Options   Quote Karlchen Quote  Post ReplyReply Direct Link To This Post Posted: 19 November 2006 at 4:34am
Good morning, kahanlon.

I am sorry if this has been beat to death, but I did search for this.

Never mind. As no forum search offers a way to search for a multiline text, you had little chance of finding all the sample batches inside the PSTools forum.

set srvr=%1

psexec \\%1% cmd
e:
del *.mp3

However, after the batch file runs psexec, it will not execute the other commands until after i exit psexec (inside the cmd window), which is not what i want to do. Is what i need to do possible?


It very likely is feasible.

Provided you wish to run only one single command inside cmd.exe you may do it like follows:
set srvr=%1

:: As you set SRV=%1 I thought we will use it
:: but this is unrelated to your issue.
psexec \\%SRV% cmd.exe /c some single command here
e:
del *.mp3


Provided you wish to run several commands inside cmd.exe you may do it like follows:
Put the commands to be executed in a second batch, named "second.bat" e.g. Then proceed like this:
set srvr=%1

psexec \\%SRV% -c second.bat
e:
del *.mp3

Note:
The psexec option -c has got a different effect than the cmd.exe option /c.
There have been reports where calling a batch remotely this way would not work. In such cases, in step 1 the batch had to be copied to \\%SRV% manually beforehand and then called this way in step 2:
copy second.bat \\%SRV%\Admin$

psexec \\%SRV% cmd.exe /c second.bat


For more information on the options of psexec.exe and cmd.exe you may run psexec -? and cmd.exe /?.

Hope this helps more than it confuses ,
Karl
Back to Top
kahanlon View Drop Down
Newbie
Newbie


Joined: 19 November 2006
Online Status: Offline
Posts: 2
Post Options Post Options   Quote kahanlon Quote  Post ReplyReply Direct Link To This Post Posted: 19 November 2006 at 2:53am

I am sorry if this has been beat to death, but I did search for this.

However I am trying to run a batch file using psexec as one of the commands that goes something like this (not exactly, but it had company information)

set srvr=%1
psexec \\%1% cmd
e:
del *.mp3

However, after the batch file runs psexec, it will not execute the other commands until after i exit psexec (inside the cmd window), which is not what i want to do. Is what i need to do possible?

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down