[dba-SQLServer] OT: history of windows update

MartyConnelly martyconnelly at shaw.ca
Tue Mar 2 11:01:45 CST 2004



Billy Pang wrote:

> Ok, this is bugging me...Does anyone know how I can check to see which 
> windows updates were made to a windows 2000 server box without going 
> to the www.windowsupdate.com website?
>
> thanks in advance,
> Billy
>
This will work from Access97  using WMI versions on win2000 and up or 
you can run vbs script as per site below
Takes about 45 -60 seconds to run
You may want to modify this vba code to only print hotfixes rather than 
all software installs or dump it to a text file.
It may produce too much info to fill a textbox. By changing the computer 
name and running under admin should be able to check all machines in a 
domain
rather than  running on a local machine.

I modified this from a vbs script from url below. Lots of other useful 
vbs wmi scripts here
http://www.robvanderwoude.com
click on left hand pane "WSH" and then examples script look for HotFix
Explanation at
  
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/compmgmt/ScrCM15.asp




'needs reference set  to WMI extension library and WMI cntl library
Function hotfix(Optional strComputerName = "Local") As String
Dim objWMIService As Object
Dim colItems As Object
Dim objItem As Object
Dim colQuickFixes As Object
Dim objQuickFix As Object
Dim strcomputer As String
Dim strMsg As String
' Check command line parameters
Select Case strComputerName
    Case "Local"
        ' Default if none specified is local computer (".")
        Set objWMIService = GetObject("winmgmts://./root/cimv2")
        Set colItems = objWMIService.ExecQuery("Select * from 
Win32_ComputerSystem", , 48)
        For Each objItem In colItems
            strcomputer = objItem.Name
        Next
    Case Else
        ' Command line parameter can either be a computer name
        ' or "/?" to request online help
        strcomputer = strComputerName
        If InStr(strcomputer, "?") > 0 Then Syntax
  
End Select

' Header line for screen output
strMsg = vbCrLf & "Hotfixes installed on " & strcomputer & ":" & vbCrLf 
& vbCrLf

' Enable error handling
On Error Resume Next

' Connect to specified computer
Set objWMIService = 
GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strcomputer & 
"/root/cimv2")
' Display error number and description if applicable
If Err Then ShowError

' Query hotfixes
Set colQuickFixes = objWMIService.ExecQuery("Select * from 
Win32_QuickFixEngineering")
' Display error number and description if applicable
If Err Then ShowError

' Prepare display of results
For Each objQuickFix In colQuickFixes
    strMsg = strMsg _
           & "    Description:       " _
           & objQuickFix.Description & vbCrLf _
           & "    Hot Fix ID:        " _
           & objQuickFix.HotFixID _
           & "    Installation Date: " _
           & objQuickFix.InstallDate _
           & "    Installed By:      " _
           & objQuickFix.InstalledBy & vbCrLf & vbCrLf
Next

' Display results
strMsg = strMsg & vbCrLf & strMsg
hotfix = strMsg
Set objWMIService = Nothing
Set colItems = Nothing
Set objItem = Nothing
Set colQuickFixes = Nothing
Set objQuickFix = Nothing
'Done
End Function


Sub ShowError()
Dim strMsg As String
    strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
             Err.Description & vbCrLf & vbCrLf
     Debug.Print strMsg
     MsgBox strMsg
    Syntax
End Sub


Sub Syntax()
Dim strMsg As String

    strMsg = strMsg & vbCrLf _
           & "HotFixes.vbs,  Version 1.00" & vbCrLf _
           & "List installed hotfixes for any computer on the network" _
           & vbCrLf & vbCrLf _
           & "Usage:  CSCRIPT  //NOLOGO  HOTFIXES.VBS  [ computer_name ]" _
           & vbCrLf & vbCrLf _
           & "Where:  " & Chr(34) & "computer_name" & Chr(34) _
           & " is the optional name of a remote computer" & vbCrLf _
           & "                        (default is local computer name)" _
           & vbCrLf & vbCrLf _
           & "Based entirely on Microsoft TechNet Script " _
           & "Center's sample script:" & vbCrLf _
           & "http://www.microsoft.com/technet/treeview/default.asp?" _
           & "url=/technet/scriptcenter/compmgmt/ScrCM15.asp" _
           & vbCrLf & vbCrLf _
           & "Modified by Rob van der Woude" & vbCrLf _
           & "http://www.robvanderwoude.com"
    Debug.Print strMsg
    MsgBox strMsg
End Sub

Function software() As String
Dim strcomputer As String
Dim objWMIService As Object
Dim colFeatures As Object
Dim objFeature As Object
Dim strMsg As String
Dim lFeatureCount As Long
strcomputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
Set colFeatures = objWMIService.ExecQuery _
             ("Select * from Win32_SoftwareFeature")
strMsg = ""
lFeatureCount = 0
For Each objFeature In colFeatures
lFeatureCount = lFeatureCount + 1
Debug.Print "Accesses: " & objFeature.Accesses
Debug.Print "Attributes: " & objFeature.Attributes
Debug.Print "Caption: " & objFeature.Caption
Debug.Print "Description: " & objFeature.Description
Debug.Print "Identifying Number: " & objFeature.IdentifyingNumber
Debug.Print "Install Date: " & objFeature.InstallDate
Debug.Print "Install State: " & objFeature.InstallState
Debug.Print "LastUse: " & objFeature.LastUse
Debug.Print "Name: " & objFeature.Name
Debug.Print "ProductName: " & objFeature.ProductName
Debug.Print "Vendor: " & objFeature.Vendor
Debug.Print "Version: " & objFeature.Version

strMsg = strMsg & vbCrLf & "Accesses: " & objFeature.Accesses
strMsg = strMsg & vbCrLf & "Attributes: " & objFeature.Attributes
strMsg = strMsg & vbCrLf & "Caption: " & objFeature.Caption
strMsg = strMsg & vbCrLf & "Description: " & objFeature.Description
strMsg = strMsg & vbCrLf & "Identifying Number: " & 
objFeature.IdentifyingNumber
strMsg = strMsg & vbCrLf & "Install Date: " & objFeature.InstallDate
strMsg = strMsg & vbCrLf & "Install State: " & objFeature.InstallState
strMsg = strMsg & vbCrLf & "LastUse: " & objFeature.LastUse
strMsg = strMsg & vbCrLf & "Name: " & objFeature.Name
strMsg = strMsg & vbCrLf & "ProductName: " & objFeature.ProductName
strMsg = strMsg & vbCrLf & "Vendor: " & objFeature.Vendor
strMsg = strMsg & vbCrLf & "Version: " & objFeature.Version

Next
software = strMsg
MsgBox "Software features=" & lFeatureCount
End Function

-- 
Marty Connelly
Victoria, B.C.
Canada






More information about the dba-SQLServer mailing list