matkay521225 Posted January 16, 2007 Posted January 16, 2007 I've created a utility to install downloaded microsoft critical/security updates from a local folder. I would like for some folks to take a look at it to see if they'd do anything differently with the code. Feel free to download and play all you want. Let me know what you think. I'm just a newbie and am self tought. FYI, you can use (Windows Updates Downloader) to quickly download the updates. Windows Updates Downloader E-Mail me JD CODE;========================================================================================== ======================================== ; Set Includes #include <GUIConstants.au3> #include <file.au3> #include <Date.au3> ;=================================================================================================== =============================== ;=================================================================================================== =============================== ; Check for Admin rights and warn user if they're not detected. If Not IsAdmin() Then MsgBox(0, "Error - Admin Rights Required.", "You must have admin rights to run windows updates. Please log in with Admin rights and re-run WUI.") ; Exit EndIf ;=================================================================================================== =============================== ;=================================================================================================== =============================== ; Check the Operating System Version before proceeding. If it doesn't match testing WARN USER!!! ;MsgBox(0, "OS", "The @OSVersion variable is currently - " & @OSVersion); Used for testing... ;If @OSVersion <> "WIN_98" And @OSVersion <> "WIN_95" Then; Used for testing... Switching the comment between this line and the next will force it to fail. If @OSVersion <> "WIN_2000" And @OSVersion <> "WIN_XP" And @OSVersion <> "WIN_2003" Then MsgBox(0, "Error - Wrong OS", "WUI has only been tested using Windows 2000 SP4, Windows XP SP2, & Windows 2003 Server SP1.") ; Exit EndIf ;=================================================================================================== =============================== ;=================================================================================================== =============================== ; Initialize variables Global $Secs, $Mins, $Hour, $Time, $timer $InPutDir = @ScriptDir & "\Updates" $TotalWUs = 0 $Counter = 0 $ScriptVer = "2.0" $TotalWUs = 0 $timer = 0 $StartHour = 0 $StartMin = 0 $StartSec = 0 $EndHour = 0 $EndMin = 0 $EndSec = 0 $SROffChecked = 0 ;=================================================================================================== =============================== ;=================================================================================================== =============================== ; Initialize Hot Keys HotKeySet("{ESC}", "Terminate") HotKeySet("{F1}", "HelpButton") ;=================================================================================================== =============================== ;=================================================================================================== =============================== ; Initialize GUI Environment Opt("GUIOnEventMode", 1) ; Change to OnEvent mode. This is used to make the program sit idle until buttons are pressed. This will then execute the corresponding function. $MyForm = GUICreate("WUI v" & $ScriptVer & " - Press (F1) for Help. Press (ESC) to exit at anytime.", 622, 336, -1, -1) $Progress1 = GUICtrlCreateProgress(8, 319, 608, 11) GUICtrlSetColor(-1, 0x316AC5) $BrowseButton = GUICtrlCreateButton("Browse", 481, 133, 120, 41) GUICtrlSetFont(-1, 14, 400, 0, "Comic Sans MS") $DirLabel = GUICtrlCreateLabel("No update(s) detected... Please click the Browse button and select your Update(s) folder.", 27, 50, 581, 22) GUICtrlSetFont(-1, 10, 400, 0, "Comic Sans MS") $Group1 = GUICtrlCreateGroup("Windows Update(s) Installer v" & $ScriptVer, 8, 8, 609, 304) GUICtrlCreateLabel("Browse for Update(s)", 490, 114, 120, 17) $InstallButton = GUICtrlCreateButton("Install Selected Updates", 24, 96, 249, 41) GUICtrlSetFont(-1, 14, 400, 0, "Comic Sans MS") $ExitButton = GUICtrlCreateButton("Exit", 481, 209, 121, 41) GUICtrlSetFont(-1, 14, 400, 0, "Comic Sans MS") $List1 = GUICtrlCreateList("No Updates Detected", 24, 145, 249, 165, -1, $WS_EX_CLIENTEDGE) GUICtrlCreateGroup("", -99, -99, 1, 1) $HelpButton = GUICtrlCreateButton("Help", 525, 265, 32, 32) $TotalWUsDisp = GUICtrlCreateLabel($TotalWUs & " update(s) detected...", 300, 165, 170, 22) GUICtrlSetFont(-1, 10, 400, 0, "Comic Sans MS") $Group2 = GUICtrlCreateGroup("Update Information", 290, 145, 170, 150) $StartTimeDisp = GUICtrlCreateLabel("Start Time - 00:00:00", 300, 200, 150, 22) GUICtrlSetFont(-1, 10, 400, 0, "Comic Sans MS") $EndTimeDisp = GUICtrlCreateLabel("End Time - 00:00:00", 300, 230, 150, 22) GUICtrlSetFont(-1, 10, 400, 0, "Comic Sans MS") $TotalTimeDisp = GUICtrlCreateLabel("Total Time - 00:00:00", 300, 260, 150, 22) GUICtrlSetFont(-1, 10, 400, 0, "Comic Sans MS") $SROffCheckBox = GUICtrlCreateCheckbox ("Turn System Restore OFF", 300, 105, 150, 20) GUICtrlSetTip(-1,"This will speed up Installation(s)" & @LF & "It simply turns off the service and" & @LF & "it will turn on after the next reboot.");Tip text that will be displayed when the mouse is hovered over the control. ;$CheckSROff = GUICtrlCreateCheckbox ("Turn System Restore OFF", 300, 95, 150, 20) ;GUICtrlCreateLabel("This will speed up installs and will turn back ON after rebooting.", 300, 114, 159, 27) ;GUICtrlSetFont(-1, 8, 400, 0, "Comic Sans MS") ;=================================================================================================== =============================== ;=================================================================================================== =============================== ; Set GUI Events GUICtrlSetOnEvent($ExitButton, "ExitButton") GUICtrlSetOnEvent($HelpButton, "HelpButton") GUICtrlSetOnEvent($BrowseButton, "BrowseButton") GUICtrlSetOnEvent($InstallButton, "InstallButton") GUICtrlSetOnEvent($SROffCheckBox, "SystemRestoreCheckBox") GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ;GUICtrlSetTip ( controlID, tiptext );Tip text that will be displayed when the mouse is hovered over the control. ;=================================================================================================== =============================== ;=================================================================================================== =============================== ; Initialize GUI GUISetState(@SW_SHOW) ;=================================================================================================== =============================== ;=================================================================================================== =============================== ; Start MAIN If FileExists ($InPutDir) Then ;MsgBox(0,"title", "Found the $InPutDir - " & $InPutDir); For testing... GUICtrlSetData($DirLabel, $InPutDir); Updates folder has been found. Set the Dirlabel display text to the inputdir variable. IE, display what was found. FileSearch(); Call the function to return the totalwus variable so the total updates detected can be displayed. GUICtrlSetData($TotalWUsDisp, $TotalWUs & " update(s) detected..."); Display total updates detected. ; MsgBox(0,"title", "Was not able to find the $InPutDir - " & $InPutDir); For testing... EndIf While 1 Sleep(1000); Idle around WEnd ; End MAIN ;=================================================================================================== =============================== ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FUNCTION(S) SECTION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func HelpButton() MsgBox(0,"WUI v" & $ScriptVer & " - Help", "Windows Update(s) Installer v" & $ScriptVer & @LF _ & "================================" & @LF _ & "" & @LF _ & "BE CAREFULL --- WUI Detects EXE files. It does NOT know the difference between notepad.exe & windowsupdate.exe." & @LF _ & "It's very important that you only put windows update exe files into your Updates folder." & @LF _ & "----------------------------------------------------------------" & @LF _ & "WUI will detect a folder specifically named (Updates) located in the same directory as the WUInstaller.exe" & @LF _ & " Example:" & @LF _ & " C:\Temp\WUInstaller.exe" & @LF _ & "" & @LF _ & " C:\Temp\Updates\Update1.exe" & @LF _ & " C:\Temp\Updates\Update2.exe" & @LF _ & " C:\Temp\Updates\Update3.exe" & @LF & @LF _ & "If WUI is not able to detect an Updates folder you must browse to a folder containing your windows updates." & @LF _ & "----------------------------------------------------------------" & @LF _ & "Your updates must be pre-downloaded. WUI does NOT download any updates for you." & @LF _ & "Check out Windows Updates Downloader to download your updates. It's and excellent & free tool." & @LF _ & "You can find it @ http://wud.jcarle.com/" & @LF _ & "----------------------------------------------------------------" & @LF _ & "Turning off System Restore." & @LF _ & "This will cause the installation of your windows updates to speed up since they'll no longer have to create a restore point." & @LF _ & "WUI only turns off the System Restore service. It will automatically start up on the next system boot." & @LF _ & "----------------------------------------------------------------" & @LF _ & "WUI has only been tested with Windows XP SP2 and Windows 2003 Server SP1." & @LF _ & "The differences between operating systems and optional updates compared to critical updates are their command line switches." & @LF _ & "" & @LF & @LF _ );Generate Help Message EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func BrowseButton() ;MsgBox(0, "You pressed the browse button. InPutDir is currently.",$InPutDir); For testing... $Folder = FileSelectFolder("Choose folder containing your update exe's.", "") If @error <> 1 Then $InPutDir = $Folder GUICtrlSetData($DirLabel, $InPutDir) FileSearch() GUICtrlSetData($TotalWUsDisp, $TotalWUs & " update(s) detected...") EndIf ;MsgBox(0, "GUI Event", "You pressed the Browse button!"); For testing... ;MsgBox(0, "You selected the following folder.",$InPutDir); For testing... EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func InstallButton() ;MsgBox(0, "GUI Event", "You clicked Install!"); For testing... $i = 0 FileSearch() $search = FileFindFirstFile($InPutDir & "\*.exe") $Counter = 100 / $TotalWUs If $search = -1 Then ;MsgBox(0, @ScriptName & " - Error", "No Windows Updates were found in the given path." & @LF & @LF & $InPutDir); For testing... ;GUICtrlSetData($DirLabel, "Updates not found...") ;MsgBox(48, @ScriptName & " - Error", "No Windows Update files were found in the updates folder." & @LF & $InPutDir & @LF & @LF & "Please make sure that all of the exes are located in the updates folder and re-run this program.") Else If $SROffChecked = 1 Then TurnSystemRestoreOFF(); If the user has opted to turn off system restore by checking the box, execute function to turn it off. ;AdlibEnable("myadlib", 200);Enable AdLib section to handle error(s). ;Start timer $timer = TimerInit() AdlibEnable("MyAdLib", 50);Enable AdLib section to handle timer. ;GUICtrlSetData($StartTimeDisp, "Start Time - " & $Time) $StartHour = @HOUR $StartMin = @MIN $StartSec = @SEC $StartTime = "Start Time - " & $StartHour & ":" & $StartMin & ":" & $StartSec GUICtrlSetData ($StartTimeDisp, $StartTime) While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If @OSVersion = "WIN_2000" And $file = "aIE6Installer.exe" Then $Execute = ($InPutDir & "\" & $file) ElseIf @OSVersion = "WIN_2000" And $file = "zqchain.exe" Then $Execute = ($InPutDir & "\" & $file) Else $Execute = ($InPutDir & "\" & $file & " /passive /norestart /overwriteoem /nobackup") EndIf If $i > 100 Then $i = 100 GUICtrlSetData ($Progress1,$i) ExitLoop Else $i = $i + $Counter EndIf GUICtrlSetData ($Progress1,$i) ; """""""""""""""""""""""""""""""" RunWait($Execute); Comment this out for testing without installing any updates. It will keep the windows updates from installing. ;Sleep(100); Un-Comment this out for testing the progress bar. It will simulate installations. ; """""""""""""""""""""""""""""""" ;MsgBox(0,"title", "Execute = " & $Execute) WEnd ;Set the Completion time of the installations ;GUICtrlSetData($EndTimeDisp, "End Time - " & $EndTime) AdlibDisable() $EndHour = @HOUR $EndMin = @MIN $EndSec = @SEC $EndTime = "End Time - " & $EndHour & ":" & $EndMin & ":" & $EndSec GUICtrlSetData ($EndTimeDisp, $EndTime) MsgBox(0,"Installation Complete", "The Windows Updates have been installed. Please REBOOT this system.") EndIf ;If $i => 100 Then Exit; Exit program once installs are complete. MIGHT REMOVE THIS OPTION. IE, LET PROGRAM KEEP RUNNING AFTER INSTALLS. EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func SystemRestoreCheckBox() $SROffChecked = BitAnd(GUICtrlRead($SROffCheckBox),$GUI_CHECKED); Zero 0 = UnChecked / One 1 = Checked. ;MsgBox(0, "System Restore CheckBox Test", $SROffChecked) EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func TurnSystemRestoreOFF() RunWait('net stop "srservice"'); This will turn System Restore off. EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func ExitButton() ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, ;and @GUI_WINHANDLE would equal $mainwindow ;MsgBox(0, "GUI Event", "You clicked Exit! Exiting..."); For testing... Exit EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func CLOSEClicked() ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, ;and @GUI_WINHANDLE would equal $mainwindow ;MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting..."); For testing... Exit EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Find all exe files located in the $InPutDir path / updates folder. Func FileSearch() $TotalWUs = 0 GUICtrlSetData($List1, "") $search = FileFindFirstFile($InPutDir & "\*.exe") ; Check if the search was successful. If $search = -1 Then MsgBox(0, @ScriptName & " - Error", "No Windows Updates were found in the given path." & @LF & @LF & $InPutDir); For testing... GUICtrlSetData($DirLabel, "No update(s) detected... Please click the Browse button and select your Update(s) folder.") ;MsgBox(48, @ScriptName & " - Error", "No Windows Update files were found in the updates folder." & @LF & $InPutDir & @LF & @LF & "Please make sure that all of the exes are located in the updates folder and re-run this program.") Else ; Count number of exe files located and populate $List1 While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $TotalWUs = $TotalWUs + 1 GUICtrlSetData($List1, $file & "|") ;MsgBox(4096, "File:", $file & " Counting " & $TotalWUs); Used for testing... WEnd EndIf FileClose($search); Close the search handle EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Hot Key set to (F1) will execute the help function. Func Help() Exit 0 EndFunc ; Hot Key set to (ESC) will automatically exit the program. Func Terminate() Exit 0 EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx AdLib SECTION xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Func MyAdLib() ;Increments the timer. _TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs ) Local $sTime = $Time ; save current time to be able to test and avoid flicker.. $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs) If $sTime <> $Time Then GUICtrlSetData($TotalTimeDisp, "Total Time - " & $Time) ;Accounts for errors in installations. If WinExists("KB","error") Then WinActivate("KB","error") Send("{ENTER}") EndIf If WinExists("KB","AVAILABLE SWITCHES") Then WinActivate("KB","AVAILABLE SWITCHES") Send("{ENTER}") EndIf If WinExists("Windows Script","Command line option syntax error") Then WinActivate("Windows Script","Command line option syntax error") Send("{ENTER}") EndIf EndFunc ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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