Windows Updates

Usage:

[Number of critical updates]
type=integer
command=cscript /b "check_updates.vbs"
result_pattern=Critical Updates: ([[:digit:]]+)
timeout=120

Code:

Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()

WScript.StdOut.WriteLine "Searching for updates..."

Set searchResult = _
updateSearcher.Search("IsInstalled=0")

WScript.StdOut.WriteLine "Total: " & searchResult.Updates.Count

PreSelected = 0

For I = 0 To searchResult.Updates.Count-1
    Set update = searchResult.Updates.Item(I)
    If update.AutoSelectOnWebSites then
        PreSelected = PreSelected + 1
    End If
Next

WScript.StdOut.WriteLine "Selected by Microsoft: " & PreSelected

WScript.StdOut.WriteLine "By category:"

ListCategories searchResult.RootCategories, "  "

sub ListCategories(categories, prefix)
    For J = 0 To categories.Count-1
        Set category = categories.Item(J)
        WScript.StdOut.WriteLine prefix & category.Name & ": " & category.Updates.count
    
'        For I = 0 To category.Updates.Count-1
'            Set update = category.Updates.Item(I)
'            If update.AutoSelectOnWebSites then
'                WScript.StdOut.WriteLine prefix & "x " & update.Title
'            Else
'                WScript.StdOut.WriteLine prefix & "  " & update.Title
'            End if
'        Next

        ListCategories category.Children, prefix & "  "
    Next
end sub

Example output from script:

Searching for updates...
Total: 38
Selected by Microsoft: 31
By category:
  Critical Updates: 2
  Definition Updates: 0
  Drivers: 1
  Feature Packs: 0
  Security Updates: 27
  Service Packs: 0
  Tools: 0
  Update Rollups: 2
  Updates: 6
  Microsoft: 0
    Windows: 0
      Windows Server 2003: 38