Sysinternals Homepage
Forum Home Forum Home > Sysinternals Utilities > PsTools
  New Posts New Posts RSS Feed - psexec
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

psexec

 Post Reply Post Reply
Author
Message
abudhwani View Drop Down
Newbie
Newbie


Joined: 28 June 2005
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote abudhwani Quote  Post ReplyReply Direct Link To This Post Topic: psexec
    Posted: 28 June 2005 at 5:27pm
Does anyone have a sample batch file that works for psexec. I am using perl and when I execute my command `psexec -c -f \\\\server cmd`; I get a session to the server, but my remaining script does not run. I just get a blank screen, only after I type exit does the rest of my script run. Of course this is useless since I want the script to execute on the remote server. I have tried several different statements(print, passing through array). Any help would be greatly appreciated.

--Arun
Back to Top
dotBATman View Drop Down
Newbie
Newbie
Avatar

Joined: 22 June 2005
Location: Norway
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote dotBATman Quote  Post ReplyReply Direct Link To This Post Posted: 29 June 2005 at 2:15am

Your "cmd" in the statement above should be replaced with the script you want to run.  Your server will know what to do when you tell it to run a .BAT or .CMD file...

Example: psexec -c -f \\server c:\temp\myscript.bat

Best regards,
Tor

Tor V -dotBATman-
Back to Top
abudhwani View Drop Down
Newbie
Newbie


Joined: 28 June 2005
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote abudhwani Quote  Post ReplyReply Direct Link To This Post Posted: 29 June 2005 at 9:58am
The problem is I am passing different commands through the cmd line. I want to open the cmd line remotely, run a few command s, and then close the session. I don't want a static batch file to run. My script passes differnet paramters, based on the user intervention. So basically, I want to

psexec -c -f \\\\servera cmd

run cmd1
   
run cmd2
   
close session
Back to Top
mford View Drop Down
Newbie
Newbie


Joined: 24 June 2005
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote mford Quote  Post ReplyReply Direct Link To This Post Posted: 29 June 2005 at 2:36pm
I see three solutions.

1) It's ugly, but you can force cmd to run a bunch of things in one "command"

psexec -c -f\\server cmd /c "cmd1 && cmd2 && cmd3"

2) generate a batch script to run (and have psexec copy it over). this won't work if you're relying on psexec to copy each individual file. but if you aren't, this works. I'm cheating and using cmd to write the file for brevity.

foreach arg in WScript.Arguments()
set oshell = createobject("WScript.Shell")
oShell.Run "cmd /c echo " & arg & " >> helper.bat",,true
next

oShell.Run("psexec -c -f \\servera helper.bat"),,true)

3) better yet, just have it connect for each command individually. There's only a small overhead for each connection, and if you're doing something where you're worrying about that you probably shouldn't be just using psexec.

You can do this in a batch file, but I can never remember the for loop syntax so here it is in vbscript.

foreach arg in WScript.Arguments()
set oShell = createobject("WScript.Shell")
oShell.Run "psexec -c -f \\servera " & arg,,1
next

That should work. I wrote the code without testing, though, but you can find similar examples easily enough, or do it in batch.

Back to Top
jayaram View Drop Down
Newbie
Newbie


Joined: 13 May 2013
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote jayaram Quote  Post ReplyReply Direct Link To This Post Posted: 28 June 2013 at 12:47pm

Currently I am using psexec for multiple times to run different commands or batch scripts, but i want to ensure that after my task done, wanted to close all sessions opened by psexec!!!

any help is very appreciated....

Thanx,
Jai
Jai.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down