Announcement

Collapse
No announcement yet.

Script to Check for Hotfix, and Install

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to Check for Hotfix, and Install

    I don't know if anyone else was effected by the Conflicker worm...but I had a throw some stuff together for quick patching, along with my previous post about removing the scheduled tasks. Maybe this will be useful to someone...I can't remember where I got everything with the code (sorry)...but it came together nicely:

    Code:
    On Error Resume Next
    
    strComputer = "." 
    
    strHotfix = "KB958644"
    
    strPatchPath = "servername\share$"
    
    strWinXp = "\WindowsXP-KB958644-x86-ENU.exe"
    strWin2000 = "\Windows2000-KB958644-x86-ENU.EXE"
    strWinServer2003 = "\WindowsServer2003-KB958644-x86-ENU.exe"
    
    strSwitches = " /u /z"
    
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\"_
        & strComputer & "\root\cimv2")
    
    Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
       For Each objOS in colOSes
    	If (InStr(1,objOS.Caption, "XP", 1)) Then
    		If isinstalled(strcomputer, strHotfix) Then
    			msgbox "Patch is already installed!"
    		Else
        			strCmd = chr(34) & "\\" & strPatchPath & strWinXP & Chr(34) & strSwitches
    			msgbox "Patch is not installed! Press OK to continue installing."
    
    			RunPatch
    		End If
    	ElseIf (InStr(1,objOS.Caption, "2000", 1)) Then
    		If isinstalled(strcomputer, strHotfix) Then
    			msgbox "Patch is already installed!"
    		Else
        			strCmd = chr(34) & "\\" & strPatchPath & strWin2000 & Chr(34) & strSwitches
    			msgbox "Patch is not installed! Press OK to continue installing."
    
    			RunPatch
    		End If
    	ElseIf (InStr(1,objOS.Caption, "2003", 1)) Then
    		If isinstalled(strcomputer, strHotfix) Then
    			msgbox "Patch is already installed!"
    		Else
        			strCmd = chr(34) & "\\" & strPatchPath & strWinServer2003 & Chr(34) & strSwitches
    			msgbox "Patch is not installed! Press OK to continue installing."
    
    			RunPatch
    		End If
    	End If
       Next
    
    Function isInstalled(strComputer,srtHotfix)
    	isinstalled = false
    	Set objWMI = GetObject("WinMGMTS://" & strComputer & "/Root/CIMv2")
    		strWQL = "SELECT * FROM Win32_QuickFixEngineering WHERE HotFixID = '" & strHotfix & "'"
    	Set colResults = objWMI.ExecQuery(strWQL)
    		For Each objItem In colResults
    			isinstalled = true
    		Next
    	If isinstalled = true then isinstalled = true
    	If IsObject(objItem) Then Set objItem = Nothing
    	If IsObject(objWMI) Then Set objWMI = Nothing
    End Function
    
    Function RunPatch
        Command = strCmd
        WSHShell.Run Command,1,True
    End Function
    
    wscript.quit(0)
    Last edited by ekrengel; 17th March 2009, 21:55. Reason: Changed Runpatch function to wait for install to finish
Working...
X