Jump to content

Recommended Posts

Posted (edited)

This was written so the security guy could give me a zip file full of all the new approved KBs for XP and svr 2003 and this would deploy and run them (as long as they use update.exe, some office and IE patches have to be ran after the array with COTS items in the same fashion as Adobe Reader in the example).

I welcome any suggestions at all.

+1 to weapon X for the recursive file search function

;;;;KB RUNNER
;;;;
;;;;to compile you need these items relative to the .au3:
;;;;
;;;;A directory named 'XP' that contains all XP hotfixes zipped and named = KBs.zip
;;;;A directory named 'SVR' that contains all Server 2003 zipped and named = KBs.zip
;;;; updating.bmp 
;;;;adobe reader 9.3.3 msp
;;;;------------------------------------------------------------------------------------------------------------------------


#AutoIt3Wrapper_Icon=*.ico
#Include <GUIConstantsEx.au3>
#Include <WindowsConstants.au3>
#Include <StaticConstants.au3>
#Include <AviConstants.au3>
#include <Array.au3>
#include <GuiToolTip.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

DirRemove ("c:\temp1\" , 1)                                                             
DirRemove ("c:\temp2\" , 1)
sleep (1000)                                                                            
Dircreate ("c:\temp1")                                                                  
Dircreate ("c:\temp2")
FileInstall ("updating.bmp" , "c:\temp1\" , 1)                                                      
SplashImageOn ("","c:\temp1\updating.bmp",@DesktopWidth, @DesktopHeight, 0, 0,1)                    
tooltip ("Unpacking and Preparing the System for Update" , "" , "" , "KBrunner" , 1 , 4)            

If @OSVersion="WIN_XP" then                                                                 
FileInstall (".\XP\KBs.zip" , "c:\temp1\" , 1)                                              
ElseIf @OSVersion="WIN_2003" then                                                           
    FileInstall (".\SVR\KBs.zip" , "c:\temp1\" , 1)                                         
Else                                                                                        
    tooltip ("Operating System not Supported, Exiting." , "" , "" , "KBrunner" , 3 , 4)     
sleep (5000)
exit

EndIf

$log = FileOpen("C:\temp1\log.txt" , 1)                                             
$zip = FileGetShortName (@ProgramFilesDir & '\Winzip\Winzip32.exe')                 
Runwait("cmd" & " /c " & $zip &" -min " &"-e "  & "C:\temp1\KBs.zip "& "c:\temp2\") 
$Array = RecursiveFileSearch ("c:\temp2\")                                          
$REG = RecursiveFileSearch1 ("c:\temp2\")
sleep (2000)                                                                        
AdlibRegister ("_adlib_check", 1000)                                                
_KBarray()                                                                          
sleep (2000)                                                                        
;;;;--------------------end of KB INSTALL ACTIONS--------------------------------------
;;;;-------------------add any additional install lines here------------------------

fileinstall ("AdbeRdrUpd933_all_incr.msp", "C:\temp2\", 1)
sleep (2000)
runwait ("cmd /c" & " C:\temp2\AdbeRdrUpd933_all_incr.msp /quiet /norestart")
sleep (5000)

;;;;--------------------begins cleaning up------------------------------

DirRemove ("c:\temp2\" , 1)                                                         
FileDelete ("c:\temp1\KBs.zip")                                                     
splashoff()                                                                         
sleep (500)                                                                         
FileDelete ("c:\temp1\updating.bmp")                                            
run ("notepad.exe " & "c:\temp1\log.txt")                                           
exit                                                                                

;;;;;;;;;;;;;RUNNING THE ARRAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FUNC _KBarray()

Dim $err


If @OSVersion="WIN_XP" then                                                                 
    $KB = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP4\"                   
ElseIf @OSVersion="WIN_2003" then                                                           
    $KB = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows Server 2003\SP3\"          
endif

$size1 = UBound ($reg) - 1                  
For $i = 1 to $size1 step +1                
    
$size = UBound ($Array) - 1                 
For $i = 1 to $size step +1 
                                 
    $err=0                       
    
tooltip ("Checking " & $KB & $reg[$i] , "" , "" , "KBrunner" , 1 , 4)   
sleep (1500)
    RegRead($KB & $reg[$i], "")                             
    if @error > 0 Then                                      
tooltip ("Installing " & $reg[$i] , "" , "" , "KBrunner" , 1 , 4)
$err=runwait ($Array[$i] & " -z"&" -m")     
Else
    tooltip ($reg[$i] & " is already installed, skipping to next item" , "" , "" , "KBrunner" , 1 , 4)  
    sleep (2000)
    endif
if $err = 0 Then
    FileWrite ($log, $Array[$i] &" Installed successfully or was already installed "& @CRLF)     
ElseIf $err = 3010 Then
    FileWrite ($log, $Array[$i] &" Installed successfully, this item requires a reboot to take effect "& @CRLF)  
Else
    FileWrite ($log, $Array[$i]  &" Exited with an error code of "& $err & @CRLF)               
Endif

Next
Next
Endfunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;==>RUNNING THE ARRAY



;;;:::::WEAPON X's - RECURSIVE FILE SEARCH - PULLS FULL DIRECTORY AND NAME:::::::::::::::::::::::::::
Func RecursiveFileSearch ($startDir, $depth = 0)

If $depth = 0 Then Global $RFSstring = ""
    
$search = FileFindFirstFile($startDir & "\*.*")
If @error Then Return

;Search through all files and folders in directory
While 1
$next = FileFindNextFile($search)
If @error Then ExitLoop

;If folder, recurse
If StringInStr(FileGetAttrib($startDir & "\" & $next), "D") Then
RecursiveFileSearch ($startDir & "\" & $next, $depth + 1)
Else
;Append filename to master string

$RFSstring &= $startDir & "\" & $next & "*"
EndIf
WEnd
FileClose($search)

If $depth = 0 Then Return StringSplit(StringTrimRight($RFSstring, 1), "*")

EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;==>RecursiveFileSearch

;;;:::::WEAPON X's - RECURSIVE FILE SEARCH - CROPPED FOR JUST "KB######":::::::::::::::::::::::::::
Func RecursiveFileSearch1 ($startDir, $depth = 0)

If $depth = 0 Then Global $next2 = ""
    
$search = FileFindFirstFile($startDir & "\*.*")

If @error Then Return

;Search through all files and folders in directory
While 1
$next = FileFindNextFile($search)
If @error Then ExitLoop
;If folder, recurse
If StringInStr(FileGetAttrib($startDir & "\" & $next), "D") Then
RecursiveFileSearch ($startDir & "\" & $next, $depth + 1)
Else
;Append filename to master string

$next1 = stringtrimright ($next, 4)
$next2 &= stringtrimleft($next1,15) &  "*"



EndIf
WEnd
FileClose($search)

Return StringSplit(StringTrimRight($next2, 1), "*")

    
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;==>RecursiveFileSearch - CROPPED



;;;;;;;;;;;;Function to handle the "Microsoft Certificate Services" error:::::::::::::::::::::::
func _adlib_check()
    local $wintitle = "Microsoft Certificate Services"         
    ; activate the window if it exists
    if winexists ($wintitle) and not winactive ($wintitle) then   
        winactivate ($wintitle)                                     
        sleep (500)                                                 
    endif
    ; send enter if the window is active
    if winactive ($wintitle) then                               
        send ("{enter}")                                        
        sleep (1000)                                            
    endif
endfunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;==>RFunction for the "Microsoft Certificate Services" error
Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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...