Jump to content

Recommended Posts

Posted

Hey guys !
I got a little problem with using quotes to pass an exit code.
I'm using psexec to execute cmd on a remote computer but i can't get back the good return code.

If i m using this one it works, but the return code is the one i need.

$ps = Run(@ScriptDir & "\psexec.exe \\" & $comp & " " & GUICtrlRead($par) & " /accepteula cmd /c "& GUICtrlRead($cmd),@ScriptDir,@SW_HIDE)

Let's suppose i got :

$cmd = "del c:\test_file.txt"

If the file exist it works and return 0, but if the file does not exist it return 0 too cause the cmd command executed.
So i tried in dos and i need to use this command :

psexec \\Remote_Comp "cmd /c del C:\test_file.txt"

So i updated the code : 

$ps = Run(@ScriptDir & "\psexec.exe \\" & $comp & " /accepteula 'cmd /c " & GUICtrlRead($cmd)"'",@ScriptDir,@SW_HIDE)

But Autoit say the expression is wrong, what am i missing ?
Thanks for help !

Posted

Something like this:

Local $sComputerName = @ComputerName
Local $sTempDir = @TempDir & "\Some Dir with Spaces"
If FileExists($sTempDir) = 0 Then DirCreate($sTempDir)
FileWrite($sTempDir & "\test_file.txt", "Some Data")
ShellExecute($sTempDir)
MsgBox(4096, "Pause", "Check file is created.")
Local $sCommand = 'del "' & $sTempDir & '\test_file.txt"'
Run('"' & @ScriptDir & '\psexec.exe" \\' & $sComputerName & ' /accepteula cmd /c ' & $sCommand, @ScriptDir, @SW_HIDE)

 

Posted

OK, seem i was not very clear in my explainations.

The part of the code i m running is :

$comp = _GUICtrlListBox_GetText($list_selected_comp, $c)
$ps = Run(@ScriptDir & "\psexec.exe \\" & $comp & " " & GUICtrlRead($par) & " /accepteula cmd /c "& GUICtrlRead($cmd),@ScriptDir,@SW_HIDE)
Sleep (1000)
If $ps <> 0 Then
    $timestamp = @HOUR & ":" & @MIN & ":" & @SEC
    _GUICtrlListBox_AddString($list_log, $timestamp & " - Error " & $ps & " on comp " & $comp)
    $nb_err += 1
Else
    $timestamp = @HOUR & ":" & @MIN & ":" & @SEC
_GUICtrlListBox_AddString($list_log, $timestamp & " - Succesful psexec on comp " & $comp)
EndIf

In this example :

$cmd = "del c:\test_file.txt"

If test_file.txt exist, it delete it and return 0.

If test_file.txt don't exist, it return 0 too cause cmd ran on remote computer.

I want $ps to return the exit code of the $cmd that ran on the remote computer.
 

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
  • Recently Browsing   0 members

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