Vofffka Posted May 21, 2009 Posted May 21, 2009 (edited) Psexec return my error codes, but not shellExecute: exemple: Script remo.exe: Exit 12345 if i run it through cmd: c:\>psexec.exe \\192.168.116.125 -u administrator -p abc123 -cf test.exe PsExec v1.94 - Execute processes remotely Copyright © 2001-2008 Mark Russinovich Sysinternals - www.sysinternals.com test.exe exited on 192.168.116.125 with error code 12345. --->>here is my error code (12345) How i can get this error code send this command through ShellExecute? ShellExecute("psexec.exe", "\\192.168.116.125 -u administrator -p abc123 -cf test.exe") ******* My attempt: In This case i got empty message $foo=ShellExecute("psexec.exe", "\\192.168.116.125 -u administrator -p abc123 -cf test.exe") Local $errcode=StdoutRead($foo) MsgBox(0,"",$errcode) Edited May 21, 2009 by Vofffka
Developers Jos Posted May 21, 2009 Developers Posted May 21, 2009 $rc = ShellExecuteWait() ? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Vofffka Posted May 21, 2009 Author Posted May 21, 2009 $rc = ShellExecuteWait() ?Tested, the same result From Help File for functions ShellExecute and ShellExecuteWait:Return ValueSuccess: Returns the exit code of the program that was run. Failure: Returns 0 and sets @error to non-zero. Therefore both variants with ShellExecute and ShellExecuteWait will not return my error codes, i don't know how do it(
Developers Jos Posted May 21, 2009 Developers Posted May 21, 2009 (edited) Ok, looks like psexec doesn't set its own RC to the remote shelled programs RC. You will have to capture the STDOUT/STDERR information and retrieve it from there. Look at StdOutRead()/StdErrRead() in the helpfile. Jos Edited May 21, 2009 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Vofffka Posted May 22, 2009 Author Posted May 22, 2009 (edited) Ok, looks like psexec doesn't set its own RC to the remote shelled programs RC. You will have to capture the STDOUT/STDERR information and retrieve it from there. Look at StdOutRead()/StdErrRead() in the helpfile. Jos $foo=ShellExecute("psexec.exe", "\\192.168.116.125 -u administrator -p abc123 -cf test.exe") Local $errcode=StdoutRead($foo) ;also checked with StdErrRead() MsgBox(0,"",$errcode) result is the same. Perhaps there is an easer way to realize this task. My scheme: 1. i have control.script that reading parameters from a config file 2. after that the control.script uploading on the remote boxes other installation scripts and run them with parameters ShellExecute("psexec.exe", "\\192.168.116.125 -u administrator -p abc123 -cf test.exe firstparm secondparm etc") 3. this installation scripts do something and me need to get response from them - result of execution Edited May 22, 2009 by Vofffka
Developers Jos Posted May 22, 2009 Developers Posted May 22, 2009 Have you checked the example in the helpfile for StdOutRead() ? Don't think it is coded this way in there. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Vofffka Posted May 22, 2009 Author Posted May 22, 2009 Have you checked the example in the helpfile for StdOutRead() ? Don't think it is coded this way in there. Jos Thank you very match, Jos. My code: $foo=Run(@ComSpec & " /k psexec.exe \\"&$ip&" -u "&$login&" -p "&$passwd&$organization, @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $line While 1 $line = StderrRead($foo) If @error Then ExitLoop if $line Then MsgBox(0, "STDERR read:", $line) EndIf Wend It's really work:)
herewasplato Posted May 22, 2009 Posted May 22, 2009 I do not think that there is any benefit to running psexec via comspec.Also, psexec was updated 07 May 2009http://technet.microsoft.com/en-us/sysinte...s/bb897553.aspx$psexecPATH = '"C:\Program Files\PStools\psexec.exe"' $psexec_switches = "-i -d" $computerNAME = "" $user = "" $psswd = "" $cmd = "notepad.exe" $cmd_arguments = "" $sp = " " $user = " -u " & $user $psswd = " -p " & $psswd $psexec = $psexecPATH & $sp & $psexec_switches & $sp $comp = "\\" & $computerNAME & $user & $psswd & $sp $final = $psexec & $comp & $cmd & $sp & $cmd_arguments ;~ MsgBox(0,"",$final) ;~ $PID = Run($final, @workingdir, @SW_HIDE, 8) $PID = Run($final, @workingdir, @SW_HIDE, 6) While 1 $line = StdoutRead($PID) If @error Then ExitLoop MsgBox(0, "StdoutRead", $line, 1) Wend While 1 $line = StderrRead($PID) If @error Then ExitLoop MsgBox(0, "StderrRead", $line) Wend [size="1"][font="Arial"].[u].[/u][/font][/size]
FATIHTALI Posted June 3, 2009 Posted June 3, 2009 I have tried I couldnt resolve my problem. I want to report if psexec can not connect remote computer. I think I must read psexec's result. How can I write to a file if psexec can not connect remote computer? I do not think that there is any benefit to running psexec via comspec. Also, psexec was updated 07 May 2009 http://technet.microsoft.com/en-us/sysinte...s/bb897553.aspx $psexecPATH = '"C:\Program Files\PStools\psexec.exe"' $psexec_switches = "-i -d" $computerNAME = "" $user = "" $psswd = "" $cmd = "notepad.exe" $cmd_arguments = "" $sp = " " $user = " -u " & $user $psswd = " -p " & $psswd $psexec = $psexecPATH & $sp & $psexec_switches & $sp $comp = "\\" & $computerNAME & $user & $psswd & $sp $final = $psexec & $comp & $cmd & $sp & $cmd_arguments ;~ MsgBox(0,"",$final) ;~ $PID = Run($final, @workingdir, @SW_HIDE, 8) $PID = Run($final, @workingdir, @SW_HIDE, 6) While 1 $line = StdoutRead($PID) If @error Then ExitLoop MsgBox(0, "StdoutRead", $line, 1) Wend While 1 $line = StderrRead($PID) If @error Then ExitLoop MsgBox(0, "StderrRead", $line) Wend Startup Agent It is my small Startup Agent. You can install programs on startup Domain pc without Admin rights.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now