Jump to content

Using PSExec


Recommended Posts

  • Moderators

Tigerweld, can you please provide a little more insight as to what you mean by "won't run"? The code seems to be working just fine for me; you simply did not provide a way to capture the return from psexec. Is that what you are after, or are you receiving an error?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

PSExec is a command line tool. If you want some visual representation of what it is doing, you have to code that in. Try this to illustrate what I mean:

$ipAddress = InputBox("IP or Host", "Enter IP or Hostname","","")
$sRemoteLocalPath = "c:\temp\"
$LocalFile = "uninstall_java.bat"

Run('C:\PsExec.exe \\' & $ipAddress & ' ' & $sRemoteLocalPath & $LocalFile & ' > C:\Temp\My.log', "", @SW_HIDE)

Notice that it outputs to a log file - you'll find this in the temp directory on the machine you're connecting to. You can choose another location for the log file, but this should illustrate what I'm getting at.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

It can be done. The script that I provided works for me. I would suggest you begin by removing the variables from your script. Something like this:

Run('C:\PsExec.exe \\10.10.10.1 C:\Temp\Uninstall_java.bat > C:\Temp\My.log', "", @SW_SHOW)

If that works, it has something to do with the way you're dropping your variables in there.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

What do you get if you don't use @SW_HIDE and use @ComSpec /k?

Run(@ComSpec & ' /k C:\PsExec.exe \\' & $ipAddress & ' ' & $sRemoteLocalPath & $LocalFile & ' > C:\Temp\My.log')

Never use @SW_HIDE until you know the command is working the way you want it to. Otherwise, you're just guessing as to what is happening.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Use the full path to where the program is located, that was an example.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

Add the variables in one at a time to figure out which one is causing you the problem. Go from this:

1.Run('C:\PsExec.exe \\10.10.10.1 C:\Temp\Uninstall_java.bat > C:\Temp\My.log', "", @SW_SHOW)

To this:

1.Run('C:\PsExec.exe \\' & $ipAddress & ' C:\Temp\Uninstall_java.bat > C:\Temp\My.log', "", @SW_SHOW)

If this works, add the next variable:

1.Run('C:\PsExec.exe \\' & $ipAddress & ' ' & $sRemoeteLocalPath & 'Uninstall_java.bat > C:\Temp\My.log', "", @SW_SHOW)

It's called troubleshooting ;)

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I also like to do logging of the run command, just before the execution, so I can check it's syntax.

ConsoleWrite('C:\PsExec.exe \\' & $ipAddress & ' ' & $sRemoeteLocalPath & 'Uninstall_java.bat > C:\Temp\My.log' & @CRLF)

Usually, something small, like forgetting a "", or omitting a space, somewhere.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

  • Moderators

Same here, jdelaney. I typically do it in a MsgBox, but same concept. Can't count the number of times I have banged my head against my desk over what turned out to be one too many or one too few spaces in a line.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...