A VB Script that checks registry for installed hotfix

You may find this usefull!
I am quite new to scripting, so I am sure that I could have done things much better than I did in this script. So I would very much appreciate any feedback, tips and comments!

The next version of this script should allow command line input aswell, so you dont have to supply a list of servernames. Also next version will check with WMI directly, instead of checking the registry.


‘Checks the registry of each computer listed in INPUT_FILE_NAME
‘for a the hotfix listed in HOTFIX
‘It uses the WMI registry provider to do this.
‘Besides writing to the screen, it writes the output to
‘the file in OUTPUT_FILE_NAME in comma delimted format, producing 2 columns:
‘the computer name, and the result of the query

’21/10/2005 Robert Kloosterhuis: v1.0
On Error Resume Next

INPUT_FILE_NAME = “serverlist.txt”
OUTPUT_FILE_NAME = “scan_hotfix_MS05_051.csv”
HOTFIX = “KB902400”

‘objFSO.OpenTextFile method uses paramater value 8 to append to file
const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002

Set StdOut = WScript.StdOut

‘Set up objFSO variable for file reading and writing operations
Set objFSO = CreateObject(“Scripting.FileSystemObject”)

‘delete OUTPUT_FILE_NAME if it already exists
Set oldfile = objFSO.GetFile(OUTPUT_FILE_NAME)

‘Set up the output file
Set objOutputFile = objFSO.OpenTextFile(OUTPUT_FILE_NAME, FOR_WRITING, true)
‘Read the input file
Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)
strComputers = objFile.ReadAll

‘Make an array out of the list it reads from the input file
arrComputers = Split(strComputers, vbCrLf)

‘setting up some initial values
DIM result
DIM noresult
result = 0
noresult = 0

‘Our main loop. Everything below this is run for every entry in the imput file
For Each strComputer In arrComputers

‘first column in the file we are writing to is the computer name.
‘Every bit of info we want to provide is ended with a comma for delimitation
objOutputFile.Write strComputer
objOutputFile.Write “,”

‘Connect to the WMI registry provider
Set objReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\” & _
strComputer & “rootdefault:StdRegProv”)
‘Error Handling If it cant connect to the WMI provider,
‘exit with the Error Description
If Err.Number <> 0 Then
Wscript.Echo strComputer & ” ” & “Error Number ” & _
Err.Number &  “: ” & Err.Description

‘The Registry path we are going to read from
strKeyPath = “SOFTWAREMicrosoftWindows NTCurrentVersionHotFix”
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
‘Everytime we run though the loop, these values are reset first.
result = 0
noresult = 0

‘If it comes across the hotfix we are looking for,
‘it changed the value for this loop
For Each Subkey in arrSubKeys

IF Subkey = HOTFIX Then
result = 1
noresult = 0

noresult = 1

End IF


‘Now we have a value, lets print some text about it,
‘both to the screen, and to our output file
IF result = 1 Then

WScript.Echo strComputer & ” ” & HOTFIX & ” installed!!!”
objOutputFile.Write HOTFIX & ” installed!!!”
WScript.Echo strComputer & ” ” & HOTFIX & ” not found!”
objOutputFile.Write HOTFIX & ” not found!”
End IF
‘End with a comma for this column
objOutputFile.Write “,”

end if

‘Start a new line


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.