Geeks With Blogs
Robert's Sysadmin Blog Unraveling the datacenter one fibre at a time

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 & "\root\default: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 = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\HotFix"
    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  


Posted on Friday, October 21, 2005 9:00 AM Security , Tech , In The Trenches | Back to top

Comments on this post: A VB Script that checks registry for installed hotfix

# re: A VB Script that checks registry for installed hotfix
Requesting Gravatar...
Brilliant! this is just what I was after
Left by Simon on Mar 31, 2009 11:16 AM

# re: A VB Script that checks registry for installed hotfix
Requesting Gravatar...
Very nice. You may be new to scripting, but out of several scripts I tried this is the only one that worked right. I had a pile of servers to check for 7 patches. You just saved me 2 hours.
Left by Gary on Dec 07, 2009 8:03 PM

# re: A VB Script that checks registry for installed hotfix
Requesting Gravatar...
What would be the registry path for Windows 7?
Left by Travis on Apr 12, 2011 10:14 AM

# re: A VB Script that checks registry for installed hotfix
Requesting Gravatar...
Thanks for the post..Can someone tell how can I set the value in serverlist.txt. Also, I am getting an error stating Wrong number of arguments or invalid property assignment in 'objOutputfile.write"...
Left by fabian on Jan 30, 2012 10:48 PM

Your comment:
 (will show your gravatar)

Copyright © Robert Kloosterhuis | Powered by: