Jump to content

Capturing output from PSEXEC


Recommended Posts

Hi,

I'm trying to get the output from psexec and display it in an edit box on my GUI.

The bit of code that I thought would do this reads as follows:

$s=Run("psexec" & " -u " & $useuser & " -p " & $usepass & " \\" & GUICtrlRead($targetInput) & " " & $command, "",@SW_MINIMIZE, 0x2)
GUICtrlSetData($outputEdit, $s)

All I get with this is 0 in the edit box (which means success afaik) what I would like sent to the edit box is:

PsExec v1.96 - Execute processes remotely

Copyright © 2001-2009 Mark Russinovich

Sysinternals - www.sysinternals.com

C:\Program Files\CA\SharedComponents\ScanEngine\InoDist.exe exited with error code 0.

so basically the same as would appear in a dos box if I was running it directly.

Any ideas what I'm doing wrong?

TIA.

Link to comment
Share on other sites

Hi,

I'm trying to get the output from psexec and display it in an edit box on my GUI.

The bit of code that I thought would do this reads as follows:

$s=Run("psexec" & " -u " & $useuser & " -p " & $usepass & " \\" & GUICtrlRead($targetInput) & " " & $command, "",@SW_MINIMIZE, 0x2)
GUICtrlSetData($outputEdit, $s)

All I get with this is 0 in the edit box (which means success afaik) what I would like sent to the edit box is:

so basically the same as would appear in a dos box if I was running it directly.

Any ideas what I'm doing wrong?

TIA.

You're returning the value that Run returns.

You need to use ControlGetText ( "title", "text", controlID ) to read from it after it is running.

From the helpfile:

Run("notepad.exe")
$var = ControlGetText("[CLASS:Notepad]", "", "Edit1")

You can use the AutoIT Window Info tool to get the instance you are looking for. Just activate it and mouseover the instance you are wanting to get info on.

Edited by Affe

[center][/center]

Link to comment
Share on other sites

To capture output from Run, you need to use $STDOUT_CHILD in the opt_flag argument. Which value, 2, you already have set in your code. You will then need to use StdoutRead to get the data you want. Editing the code you provided, try this

$iPID=Run("psexec" & " -u " & $useuser & " -p " & $usepass & " \\" & GUICtrlRead($targetInput) & " " & $command, "",@SW_MINIMIZE, 0x2)
ProcessWaitClose($iPID)
$sOutput = StringStripWS(StdoutRead($iPID), 3)
GUICtrlSetData($outputEdit, $sOutput)

I use ProcessWaitClose so I don't have worry about having a loop to get all of the data in the output stream. I use StringStripWS with option 3 to remove all leading and trailing white spaces.

Edit: Typos

Adam

Edited by AdamUL
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...