• 0

VBScript - Check to see if Microsoft Hoxfix (KB) is NOT installed


Question

Hello, I have an essential hotfix that has been deployed across our network, however it has not been installed on all the machines, and want to check which machines will need the hotfix.

 

Using VBScript, is there a way that a script that runs at startup that checks whether a specific KB is NOT installed and write the result as a file into a directory?

 

At the moment I have this:

On Error Resume Next
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_QuickFixEngineering",,48)
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
strComputerName = wshNetwork.ComputerName
 
 
For Each objItem in colItems
 
If objItem.HotfixID = "KB2590550" then
 
outFile="\\F30-CHI\D$\VBTest\" & strComputerName
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Close
 
End If
 
Next

This works perfectly for creating a file if the Hofix IS installed. However I want it to create a file if it is NOT installed.

 

Is this possible?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Add a new variable to store the 'found' state, this variable may store a value of 0 for not found and 1 for found, for example. Initialise it to 0. As you loop through the dataset you're analysing to detect whether the patch is installed, if and when the current object in the loop is the item you're looking for, change the 'found' variable state to 1 to indicate that it's been found. Once you've finished looping through the dataset and therefore have a result as to whether or not the item was found, you can then do something based on that information with a new if statement.

 

For sake of efficiency, you might also like to use a 'break' command to stop looping once you've found the item you're looking for. In VBScript there are multiple 'break' commands, each for breaking out of a different construct - 'Exit For', 'Exit Do', 'Exit Sub'.

patchFound = 0

For Each objItem in colItems
     If objItem.HotfixID = "KB2590550" then
        patchFound = 1
        Exit For
    End If
Next

If patchFound = 0 then
    //Do something (patch missing so install it...)
End If
Link to comment
Share on other sites

This topic is now closed to further replies.