Motok Posted December 16, 2019 Posted December 16, 2019 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 !
Motok Posted December 16, 2019 Author Posted December 16, 2019 Isn't that i m doing ? I m using 'cmd /c " & GUICtrlRead($cmd)"' That's single quotes around double quotes.
Shark007 Posted December 16, 2019 Posted December 16, 2019 This 'cmd /c " & GUICtrlRead($cmd)"' should be '"cmd /c " & "GUICtrlRead($cmd)"'
Subz Posted December 16, 2019 Posted December 16, 2019 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)
Motok Posted December 16, 2019 Author Posted December 16, 2019 Tried : $ps = Run('"'@ScriptDir & '\psexec.exe "' & GUICtrlRead($par) '\\' & $comp & ' /accepteula cmd /c ' & GUICtrlRead($cmd),@ScriptDir,@SW_HIDE) => Badly formated variable or macro And : $ps = Run(@ScriptDir & "\psexec.exe \\" & $comp & " /accepteula '"cmd /c " & "GUICtrlRead($cmd)"'",@ScriptDir,@SW_HIDE) => Unable to parse line.
Subz Posted December 16, 2019 Posted December 16, 2019 In your gui, you need to have the $cmd input you would need to type: del "C:\test_file.txt" Then use: $ps = Run(@ScriptDir & "\psexec.exe \\" & $comp & " /accepteula cmd /c " & GUICtrlRead($cmd), @ScriptDir, @SW_HIDE)
Motok Posted December 16, 2019 Author Posted December 16, 2019 Thanks, that's working ! I have to use RunWait to get the good exit code.
Motok Posted December 16, 2019 Author Posted December 16, 2019 Went a bit too fast, the command is now not working anymore.
FrancescoDiMuro Posted December 17, 2019 Posted December 17, 2019 @Motok Post the code you are running, and tell us exactly what is not working Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Motok Posted December 17, 2019 Author Posted December 17, 2019 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.
Subz Posted December 19, 2019 Posted December 19, 2019 Look at StdoutRead and StderrRead in help file.
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