1

I am updating an existing HTA application. The page displays records of each machine in the company that hasn't performed a backup (Via ibm tsm) within the last 3 days. I have made a button for each record that when pressed, should execute a cscript process using PSEXEC that run an exe on the target machine and passes an argument. (dsmc.exe INCREMENTAL) Now i can manually open a cmd prompt, use the \Remote cmd command to create a remote cmd, and run the application just fine. But without the extra step of creating a remote cmd prompt, and trying to

PSEXEC \\RemoteMachine cscript.exe "C:\Program Files\tivoli\tsm\baclient\dsmc.exe" INCREMENTAL

Only results in an error. I know that it should be possible to remotely execute this program and still pass in an argument but it just doesn't run. And when i create the remote cmd prompt using

PSEXEC \\RemoteMachine cmd

Any other lines in the execution script do not execute until i exit the remote cmd prompt.

Is there a secret to PSEXEC i don't understand or a way to grab an existing cmd prompt (The remote one i just created) and pass it the command to execute? Please Help

*Note, this is not my first script using PSEXEC. I typically use my VBScript to create a batch file locally with the PSEXEC Script contained, and then execute it. Never have been able to get wsshell.run to work with PSEXEC.

jay bear
  • 37
  • 1
  • 1
  • 4
  • 1. is it okay that `cscript`'s first parameter is an executable file? 2. any luck passing the commands via a temporary file `psexec \\pc @tmpfile`? – wOxxOm Jul 16 '15 at 18:07
  • Did you try the `-d` switch on the `PSEXEC` command so it doesn't wait for exiting? Also, what is the error you're seeing? – langstrom Jul 17 '15 at 17:13
  • wOxxOm - That would work for me, but not everyone running the application is a domain admin and would not work for them. I have used that method before on certain applications only admins would be using though. – jay bear Jul 17 '15 at 19:19
  • langstrom - If I remember correctly it was an error code of 12. I would try it again but i am swamped today with work and can't get into the code right now. – jay bear Jul 17 '15 at 19:20

1 Answers1

3

Here is (more or less) my syntax for using objShell.Run to work with psexec:

Set objShell = CreateObject("Wscript.Shell")
objShell.Run "cmd.exe /c ""%pathToPsexec%\psexec.exe"" -accepteula -s -i -d \\RemoteMachine cmd.exe /k ipconfig",0,True

This is just an example, but shows that you can send nested switches, etc. It's also important to understand the switches of psexec.

-accepteula - this accepts the license agreement on psexec. this isn't necessary unless you're running it for the first time and you want it to be quiet.
-s - runs as the System account of the remote computer. If you don't use this, you need to specify -u and -p if you want to run interactively. Otherwise your credentials perform a network logon
-i - specifies to run interactively. This can be omitted or a session can be specified.
-d - don't wait for the remote command to finish before moving on

langstrom
  • 1,652
  • 11
  • 14
  • Where did you learn this glory? lol Seriously though, any recommended sources for learning more about nesting psexec switches? I'll have to go back over many old programs and update them. – jay bear Jul 17 '15 at 19:21
  • 1
    Make sure you're using the latest version of psexec, also. At some point they actually made changes to the way switches are sent. It used to be less intelligent and more prone to errors. I don't remember where I learned it, just trial and error and a lot of googling. – langstrom Jul 17 '15 at 19:28
  • Okay, just got a chance to implement this and it works!!! :D You sir are amazing. The internet has been won ladies and gentlemen! All of my scripts implementing psexec are being cleaned up now. Woo! – jay bear Jul 17 '15 at 20:05