myk3 Posted May 5, 2011 Share Posted May 5, 2011 (edited) I built a gui front end for PsExec and I can not figure the last small bug out.. I can add multiple hostnames manually and everything works fine.. but when I import multiple hostnames in and then read them out all of the "deployments" fail?? Here is the code.. I disabled the "import" button until I figure out why it keeps failing.. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #Include <GuiListView.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <array.au3> #Include <File.au3> #include "filelist.au3" #RequireAdmin global $test =9999, $form1=9999, $form2=9999, $form3=9999,$Form4=9999, $ok = 9999, $cancel = 9999, $add=9999, $delete=9999, $edit=9999, $file=9999,$add1 =9999 Global $edit1=9999, $IName2=9999, $location=9999,$Location1=9999,$Location2=9999,$deploy=9999,$hostname=9999,$list2=9999,$import=9999,$hostnames=9999, $command1=9999,$sRtn=9999 global $command=9999, $FileName=9999, $file1 =9999, $switches=99991, $INAME=9999, $IName1=9999, $List1=9999, $select=9999, $deployarray[1],$exitcode,$switches1, $Label3, $temp, $ListView1 Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") $1 = 1 $message = "Pick the file you wish to install" $dir = _FileListToArrayEx(@ScriptDir & "\installers\",'*.txt',1) if FileExists(@scriptdir & "\Installers\") Then Else DirCreate(@scriptdir & "\Installers\") endif if FileExists(@scriptdir & "\Deployments\") Then Else DirCreate(@scriptdir & "\Deployments\") EndIf FileInstall("C:\Users\michael.c.chipser\Desktop\Flash Drive\boot\HTP.jpg",@TempDir&"\") SplashImageOn("Chipsers Depployment tool",@TempDir & "\htp.jpg",-1,-1,-1,-1,1) sleep(5000) SplashOff() if FileExists(@TempDir & "\htp.jpg") Then FileDelete(@TempDir & "\htp.jpg") EndIf _main() func _Main() $h =1 $Form1 = GUICreate("Patch Management", 749, 468, 186, 117) $Installers = GUICtrlCreateGroup("Installers", 8, 8, 185, 409, BitOR($GUI_SS_DEFAULT_GROUP,$BS_FLAT)) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $List1 = GUICtrlCreateList("", 16, 24, 169, 390) GUICtrlCreateGroup("", -99, -99, 1, 1) $add = GUICtrlCreateButton("Add", 8, 424, 83, 33) $delete = GUICtrlCreateButton("Delete", 112, 424, 83, 33) $Group2 = GUICtrlCreateGroup("", 200, 56, 537, 105, BitOR($GUI_SS_DEFAULT_GROUP,$BS_FLAT)) $file = GUICtrlCreateLabel("File Name: " , 208, 72,300, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $command = GUICtrlCreateLabel("Command Line: ", 208, 112,500, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1) $delpoy = GUICtrlCreateButton("Deploy Now", 656, 24, 83, 33) $edit = GUICtrlCreateButton("Edit Installer", 568, 24, 83, 33) $Name = GUICtrlCreateLabel("INSTALLER NAME", 200, 24, 250, 24) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $Group3 = GUICtrlCreateGroup("Deployments", 200, 168, 537, 289, BitOR($GUI_SS_DEFAULT_GROUP,$BS_FLAT)) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $ListView1 =GUICtrlCreateListView("Hostname|Status|Date", 208, 185, 522, 262) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1,$LVS_REPORT) GUISetState(@SW_SHOW) if $dir <> "" Then do $str = StringTrimRight($dir[$1],4) GUICtrlSetData($List1,$str) $1 += 1 until $1 = UBound($dir) endif While 1 $1 = 1 $msg = GUIGetMsg(1) if $msg = "" Then ContinueLoop endif if GUICtrlRead($List1) <> "" Then if GUICtrlRead($List1) = $select Then Else $select = GUICtrlRead($List1) GUICtrlSetData($Name,$select) $fileO = FileOpen(@ScriptDir & "\Installers\" & $select &".txt",0) $switches = FileReadLine($fileO,1) $location1 = FileReadLine($fileO,2) FileClose($fileO) $array = StringSplit($location1,"\",1) $u = UBound($array) GUICtrlSetData($file,$array[$u-1]) GUICtrlSetData($command,$array[$u-1] & " " & $switches) _GUICtrlListView_DeleteAllItems($listview1) if FileExists(@ScriptDir & "\Deployments\"& $select & ".txt") Then _FileReadToArray(@ScriptDir & "\Deployments\"& $select & ".txt",$temp) $im = 1 do GUICtrlCreateListViewItem($temp[$im],$ListView1) $im += 1 until $im = UBound($temp) $ColumnCount = _GUICtrlListView_GetColumnCount($ListView1) For $I = 0 To $ColumnCount -1 ;~ Loop through all of the columns, columns are zero based, so you have to subtract 1 from the count _GUICtrlListView_SetColumnWidth($ListView1, $I, $LVSCW_AUTOSIZE) ;~ <== this autosizes the columns Next endif $command1 = '"' &$array[$u-1] &'"'& " " & $switches endif endif switch $msg[1] case $Form1;MAIN FORM Switch $msg[0] Case $GUI_EVENT_CLOSE Exit Case $add GUISetState(@SW_disable,$Form1) _Installer() Case $delete $delete1 = MsgBox(4,"Delete?","Are you sure you want to delete """& $select &'"') if $delete1 = 6 Then if FileExists(@ScriptDir & "\installers\" & $select &".txt") Then FileDelete (@ScriptDir & "\installers\" & $select &".txt") EndIf $item2delete = ControlCommand ( "Patch Management", "", $list1, "FindString", $select) ControlCommand("Patch Management","",$list1,"DelString",$item2delete) EndIf Case $delpoy if $select = "" then ContinueLoop Else GUISetState(@SW_disable,$Form1) _deploy() endif Case $edit $edit1 = GUICtrlRead($List1) if GUICtrlRead($List1) = "" Then ContinueLoop Else $fileO = FileOpen(@scriptdir & "\installers\" & $select &".txt",0) $switches = FileReadLine($fileO,1) $location1 = FileReadLine($fileO,2) FileClose($fileO) _edit($select,$switches,$location1) endif EndSwitch case $Form2 ;ADD INSTALLER Switch $msg[0] case $file1 $location1= FileOpenDialog($message,@ScriptDir, "ALL (*.*)", 1);file browse to get the location of the patch If @error Then ContinueLoop EndIf GUICtrlSetData($Location2,$location1) case $ok if FileExists(@ScriptDir & "\installers\" & GUICtrlRead($INAME,0) &".txt") Then FileDelete (@ScriptDir & "\installers\" & GUICtrlRead($INAME,0) &".txt") $item2delete = ControlCommand ( "Patch Management", "", $list1, "FindString", $select) ControlCommand("Patch Management","",$list1,"DelString",$item2delete) EndIf $fileO = FileOpen(@ScriptDir & "\installers\" & GUICtrlRead($INAME,0) &".txt",1) FileWriteLine($fileO,GUICtrlRead($switches1)) FileWriteLine($fileO,GUICtrlRead($Location2)) FileClose($fileO) ControlCommand("Patch Management","",$list1,"addstring",GUICtrlRead($INAME,0)) GUIDelete($Form2) GUISetState(@SW_enable,$Form1) case $cancel GUIDelete($Form2) GUISetState(@SW_enable,$Form1) case $GUI_EVENT_CLOSE GUIDelete($Form2) GUISetState(@SW_enable,$Form1) EndSwitch case $Form3 ;EDIT INSTALLER Switch $msg[0] case $file1 $location1= FileOpenDialog($message,@ScriptDir, "ALL (*.*)", 1);file browse to get the location of the patch If @error Then ContinueLoop EndIf GUICtrlSetData($Location2,$location1) case $ok $IName2 = GUICtrlRead($INAME,0) if $select <> $IName2 Then if FileExists(@ScriptDir & "\installers\" & $select &".txt") Then FileDelete (@ScriptDir & "\installers\" & $select &".txt") EndIf if FileExists(@ScriptDir & "\deployments\" & $select &".txt") Then FileDelete (@ScriptDir & "\deployments\" & $select &".txt") EndIf $item2delete = ControlCommand ( "Patch Management", "", $list1, "FindString", $select) ControlCommand("Patch Management","",$list1,"DelString",$item2delete) EndIf $selects = GUICtrlRead($Label3,0) if $selects <> $switches Then if FileExists(@ScriptDir & "\installers\" & $select &".txt") Then FileDelete (@ScriptDir & "\installers\" & $select &".txt") EndIf $item2delete = ControlCommand ( "Patch Management", "", $list1, "FindString", $select) ControlCommand("Patch Management","",$list1,"DelString",$item2delete) EndIf $fileO = FileOpen(@ScriptDir & "\installers\" & GUICtrlRead($INAME,0) &".txt",1) FileWriteLine($fileO,GUICtrlRead($switches1)) FileWriteLine($fileO,GUICtrlRead($Location2)) FileClose($fileO) ControlCommand("Patch Management","",$list1,"addstring",GUICtrlRead($INAME,0)) GUIDelete($Form3) GUISetState(@SW_enable,$Form1) case $cancel GUIDelete($Form3) GUISetState(@SW_enable,$Form1) case $GUI_EVENT_CLOSE GUIDelete($Form3) GUISetState(@SW_enable,$Form1) EndSwitch case $form4 ;DEPLOY FORM switch $msg[0] Case $add1 GUICtrlSetData($List2,GUICtrlRead($hostname,0)) ;---------------------------- ;----------DEPLOY------------ ;---------------------------- Case $deploy;DEPLOY HERE GUISetState(@SW_DISABLE,$Form4) GUISetState(@SW_hide,$Form4) GUISetState(@SW_hide,$Form1) $l = 0 ProgressOn("Deployment progress","Deploying: " & $select) do $deploy1 = _GUICtrlListBox_GetText($list2, $l) if IsArray ($deployarray) = 1 Then $bound = ubound($deployarray) ReDim $deployarray[$bound+$1] $deployarray[$bound] = _GUICtrlListBox_GetText($list2, $l) endif $l += 1 until _GUICtrlListBox_GetText($list2, $l) = "" ;~ _ArrayDisplay($deployarray) $l = 1 do if $l > $bound then exitloop if $deployarray[$l] = " " Then $l +=1 ContinueLoop endif $deploy1 = $deployarray[$l] if $deploy1 = "localhost" Then $deploy1 = @ComputerName endif $var = ping($deploy1,2000) if $var then;deployment commands go here ProgressSet(50,"Copying " & $select & @CRLF & $deploy1,"Deploying: " & $select) ;~ MsgBox(0,"",$location1) $filecopy = FileCopy($location1,"\\" & $deploy1 & "\admin$\",1) if $filecopy = 0 Then FileWriteLine(@scriptdir & "\Deployments\" & $select & ".txt",$deploy1 & "|" & "COPY_ERROR" &"|" & @mday & "/" & @mon & "/" & @year & " " &@hour & ":" & @min) $l += 1 ContinueLoop EndIf ProgressSet(75,"Installing "& @CRLF &'"'& $select &'"'& " on " & $deploy1 ,"Deploying: " & $select) MsgBox(0,"",@scriptdir & "\PsExec.exe -accepteula -i \\" & $deploy1 & " " & $command1) $filerun = runwait(@scriptdir & "\PsExec.exe -accepteula -i \\" & $deploy1 & " " & $command1 ,"",@SW_HIDE) Switch $filerun case 0 $exitcode = "Success" Case else $exitcode = "Error" EndSwitch if $filerun <> 0 Then FileWriteLine(@scriptdir & "\Deployments\" & $select & ".txt",$deploy1 & "|" & $exitcode &"|" & @mday & "/" & @mon & "/" & @year & " " &@hour & ":" & @min) $l += 1 ContinueLoop endif FileWriteLine(@scriptdir & "\Deployments\" & $select & ".txt",$deploy1 & "|" & $exitcode &"|" & @mday & "/" & @mon & "/" & @year & " " &@hour & ":" & @min) $l += 1 ProgressSet(90,"Cleaning up: "& @CRLF &'"'& $select &'"' & " on "& $deploy1 ,"Deploying: " & $select) if FileExists ("\\" & $deploy1 & "\admin$\"& $array[$u-1]) then FileDelete("\\" & $deploy1 & "\admin$\"& $array[$u-1]) EndIf endif _GUICtrlListView_DeleteAllItems($listview1) if FileExists(@ScriptDir & "\Deployments\"& $select & ".txt") Then _FileReadToArray(@ScriptDir & "\Deployments\"& $select & ".txt",$temp) $im = 1 do GUICtrlCreateListViewItem($temp[$im],$ListView1) $im += 1 until $im = UBound($temp) endif Until $1 = $bound ProgressOff() ReDim $deployarray[1] GUISetState(@SW_enable,$Form4) GUISetState(@SW_enable,$Form1) GUISetState(@SW_show,$Form1) GUISetState(@SW_show,$Form4) case $import $location1 = FileOpenDialog($message,@ScriptDir, "ALL (*.*)", 1) If @error Then MsgBox(4096,"","No File(s) chosen");if there was no file selected state soand exit ContinueLoop EndIf _FileReadToArray($location1,$hostnames) if IsArray ($hostnames) then $im = 1 do GUICtrlSetData($List2,$hostnames[$im]) $im += 1 until $im = UBound($hostnames) Else MsgBox (0,"","No hostnames in the file specified") endif case $cancel GUIDelete($Form4) GUISetState(@SW_enable,$Form1) case $GUI_EVENT_CLOSE GUIDelete($Form4) GUISetState(@SW_enable,$Form1) EndSwitch endswitch WEnd EndFunc func _Installer();add $Form2 = GUICreate("Installer", 738, 160, 380, 154) $Label1 = GUICtrlCreateLabel("Installer Name: ", 16, 16, 112, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $INAME = GUICtrlCreateInput("", 128, 16, 585, 21, BitOR($GUI_SS_DEFAULT_INPUT,$WS_BORDER)) $Label2 = GUICtrlCreateLabel("Installer File: ", 16, 48, 97, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $location2 = GUICtrlCreateInput("", 129, 48, 551, 21, BitOR($GUI_SS_DEFAULT_INPUT,$WS_BORDER)) $file1 = GUICtrlCreateButton("...", 688, 48, 27, 25) $Label3 = GUICtrlCreateLabel("Switches: ", 16, 80, 73, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $switches1 = GUICtrlCreateInput("", 128, 80, 585, 21, BitOR($GUI_SS_DEFAULT_INPUT,$WS_BORDER)) $Label4 = GUICtrlCreateLabel("NOTE: Ensure you have selected the proper silent switches, otherwise the deployment may appear to hang indefinitely", 128, 104, 584, 17) GUICtrlSetColor(-1, 0xFF0000) $ok = GUICtrlCreateButton("OK", 645, 125, 27, 25) GuiCtrlSetState(-1, 512) $cancel = GUICtrlCreateButton("Cancel", 675, 125, 45, 25) GUISetState(@SW_SHOW) EndFunc func _edit($INAME1,$switches2,$location1) $Form3 = GUICreate("Installer", 738, 160, 380, 154) $Label1 = GUICtrlCreateLabel("Installer Name: ", 16, 16, 112, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $INAME = GUICtrlCreateInput($INAME1, 128, 16, 585, 21, BitOR($GUI_SS_DEFAULT_INPUT,$WS_BORDER)) $Label2 = GUICtrlCreateLabel("Installer File: ", 16, 48, 97, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $location2 = GUICtrlCreateInput($location1, 129, 48, 551, 21, BitOR($GUI_SS_DEFAULT_INPUT,$WS_BORDER)) $file1 = GUICtrlCreateButton("...", 688, 48, 27, 25) $Label3 = GUICtrlCreateLabel("Switches: ", 16, 80, 73, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $switches1 = GUICtrlCreateInput($switches2, 128, 80, 585, 21, BitOR($GUI_SS_DEFAULT_INPUT,$WS_BORDER)) $Label4 = GUICtrlCreateLabel("NOTE: Ensure you have selected the proper silent switches, otherwise the deployment may appear to hang indefinitely", 128, 104, 584, 17) GUICtrlSetColor(-1, 0xFF0000) $ok = GUICtrlCreateButton("OK", 645, 125, 27, 25) GuiCtrlSetState(-1, 512) $cancel = GUICtrlCreateButton("Cancel", 675, 125, 45, 25) GUISetState(@SW_SHOW) EndFunc func _Deploy() $Form4 = GUICreate("Targets", 406, 355, 192, 124) GUICtrlCreateLabel("Insert Hostname / IP",8,2) $Import = GUICtrlCreateButton("Import", 320, 16, 75, 25);,$WS_DISABLED) $add1 = GUICtrlCreateButton("Add", 280, 16, 35, 25) GuiCtrlSetState(-1, 512) $List2 = GUICtrlCreateList("", 8, 48, 385, 253) $deploy = GUICtrlCreateButton("Deploy Now", 240, 304, 75, 25) $cancel = GUICtrlCreateButton("Cancel", 320, 304, 75, 25) $hostname = GUICtrlCreateInput("", 8, 16, 265, 21) $deployC = GUICtrlCreateLabel($command1, 8, 330,400, 21) GUICtrlSetFont(-1, 10, 200, 0, "MS Sans Serif") GUISetState(@SW_SHOW) endfunc Func _FileCopy($fromFile,$tofile);function for the file copy.. uses the built in file copy shell app. Local $FOF_RESPOND_YES = 16 Local $FOF_SIMPLEPROGRESS = 256 $winShell = ObjCreate("shell.application") $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES) EndFunc ;---------------------------------------------------------------------------------------------------------- ; Com Error Handler ;---------------------------------------------------------------------------------------------------------- Func MyErrFunc() Local $HexNumber Local $strMsg $HexNumber = Hex($oMyError.Number, 8) $strMsg = "Error Number: " & $HexNumber & @CRLF $strMsg &= "WinDescription: " & $oMyError.WinDescription & @CRLF $strMsg &= "Script Line: " & $oMyError.ScriptLine & @CRLF MsgBox(0, "ERROR", $strMsg) SetError(1) Endfunc Edited May 6, 2011 by myk3 Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 5, 2011 Share Posted May 5, 2011 If you uncomment this _ArrayDisplay(), does show the expected values present in the $deployarray array? ;~ _ArrayDisplay($deployarray) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
myk3 Posted May 6, 2011 Author Share Posted May 6, 2011 (edited) If you uncomment this _ArrayDisplay(), does show the expected values present in the $deployarray array? ;~ _ArrayDisplay($deployarray) Yes the expected values are shown.. Also I put a message box before the $filerun = runwait(@scriptdir & "\PsExec.exe -accepteula \\"& $deploy1 & " " & $command1,"",@SW_HIDE) and It also shows the expected command.. Is there a way to pause the runwait and see what PsExec is showing as the error? Since even without the ",@SW_HIDE" it shows but then goes away way to fast for me to read the error.. I have also tried output the line to a text document but that doesn't seem to be working either.. ">test.txt" EDIT: I can get PsExec to output to a text document using 2>test.txt straight from cmd prompt but not from in autoit.. Edited May 6, 2011 by myk3 Link to comment Share on other sites More sharing options...
myk3 Posted May 6, 2011 Author Share Posted May 6, 2011 (edited) Something that I just found odd.. I can manually add multiple hostnames into the list, using the add button I have created, and this works.. However when I import hostnames with the import loop it doesn't.. Here is my loop to import the list of hostnames case $import $location1 = FileOpenDialog($message,@ScriptDir, "ALL (*.*)", 1) If @error Then MsgBox(4096,"","No File(s) chosen") ContinueLoop EndIf _FileReadToArray($location1,$hostnames) _ArrayDisplay($hostnames) if IsArray ($hostnames) then $im = 1 do GUICtrlSetData($List2,$hostnames[$im]) $im += 1 until $im = UBound($hostnames) Else MsgBox (0,"","No hostnames in the file specified") endif Here is the loop to take the values from the list into an array do $deploy1 = _GUICtrlListBox_GetText($list2, $l) if IsArray ($deployarray) = 1 Then $bound = ubound($deployarray) ReDim $deployarray[$bound+$1] $deployarray[$bound] = _GUICtrlListBox_GetText($list2, $l) endif $l += 1 until _GUICtrlListBox_GetText($list2, $l) = "" _ArrayDisplay($deployarray) Edited May 6, 2011 by myk3 Link to comment Share on other sites More sharing options...
myk3 Posted May 6, 2011 Author Share Posted May 6, 2011 (edited) Not sure if this matters.. I did an _arraydisplay after the import and after the list to array and found that the first array variable is not there.. [0]|110 [0]| The top one is during the import the bottom is during the install.. However all the other locations are the same.. EDIT: When adding the hostnames manually there is also no value in the [0] value of the array, so I don't think that is the problem. Edited May 6, 2011 by myk3 Link to comment Share on other sites More sharing options...
Balay2b Posted May 6, 2011 Share Posted May 6, 2011 friends..... Pls help me.......... how can i get text where cursor stand still with out clicking on it Link to comment Share on other sites More sharing options...
myk3 Posted May 6, 2011 Author Share Posted May 6, 2011 I just figured out the problem.. I had changed the "$location1" variable which copied the imported txt document to the remote computer and then tried to execute it.. I change the import variable to "$location2" and everything seems to be working fine.. Thanks for the help Link to comment Share on other sites More sharing options...
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