Share This Post

VB Script to Check on a Particular Patch Status

Here is a little VB Script to query WMI and to check if a particular patch is installed.

‘On Error Resume Next

strKB = Inputbox ("Enter the KB Number")
‘ in KB917537 format

x = 2

‘Create an Excel Work Sheet

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add

objExcel.Cells(1, 1).Value = "Machine Name"
objExcel.Cells(1, 2).Value = "KB"
objExcel.Cells(1, 3).Value = "Installed On"
objExcel.Cells(1, 4).Value = "Report Time Stamp"

objExcel.Range("A1:G1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit

‘Read machine names from a txt file

Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine

intRow = x

objExcel.Cells(intRow, 1).Value = strComputer

GetPatchInfo

objExcel.Cells(intRow, 4).Value = Now()

x = x + 1

Loop

Wscript.Echo "Done"

‘*********************************************************************************************************
‘Get patch Status from WMI

Sub GetPatchInfo

Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2")

Set colPatches = objWMIService.ExecQuery _
("Select * From Win32_QuickFixEngineering Where HotFixID = ‘”& strKB”’’")
For Each objPatch in ColPatches

objExcel.Cells(intRow, 2).Value = objPatch.Description
objExcel.Cells(intRow, 3).Value = objPatch.InstalledOn

Next
End Sub

Share This Post

Ying Li obtained a Master degree of Medicine in China and worked in the medical field before he came to the states in 1996. He made the career switch from troubleshooting people to troubleshooting computers after he came to the states. Not entirely a surprise there, if you know that his second preference for college is Mathematics. Ying is two times Admin Framework MVP awardee (2007-2008).His previous employment experience in the US includes UUNET, MCI WorldCom. MMC (Marsh & McLennan Companies), Merrill Lynch. He is currently employed by Related Companies as a Senior Infrastructure Engineer. He is proficient in virtually all Microsoft products (Office/Back office). His craving for efficiency naturally leads him to scripting, automation and before you know it, PowerShell! He is currently a MCSE (NT4, 2000, 2003) and MCITP Server Administrator. Ying enjoys wines and love to travel. His non work related passion is to advocate Health Living!

Leave a Reply