Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for wupdhist.vbs

(view source code of wupdhist.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim arrOperations, arrResultCodes
  4. Dim blnFilterKB
  5. Dim colHistory, objHistory, objSearcher
  6. Dim strFilterKB, strMsg, strUpd
  7.  
  8. ' Arrays to convert result numbers to their descriptions
  9. arrResultCodes = Array( "not started", "in progress", "succeeded", _
  10.                         "succeeded with errors", "failed", "aborted" )
  11. arrOperations  = Array( "", "Installation", "Uninstallation" )
  12. blnFilterKB    = False
  13. strMsg         = ""
  14.  
  15. ' Parse the command line arguments
  16. With WScript.Arguments
  17. 	If .Named.Count   > 1 Then Syntax
  18. 	If .Unnamed.Count > 1 Then Syntax
  19. 	If .Named.Exists( "KB" ) Then
  20. 		blnFilterKB = True
  21. 		strFilterKB = .Named.Item( "KB" )
  22. 		If Trim( strFilterKB ) = "" Then
  23. 			If .Unnamed.Count = 1 Then
  24. 				strFilterKB = .Unnamed(0)
  25. 			Else
  26. 				blnFilterKB = False
  27. 			End If
  28. 		End If
  29. 	Else
  30. 		If .Named.Count > 0 Then Syntax
  31. 	End If
  32. 	If .Named.Count = 0 And .Unnamed.Count = 1 Then
  33. 		blnFilterKB = True
  34. 		strFilterKB = .Unnamed(0)
  35. 		If UCase( Left( strFilterKB, 2 ) ) = "KB" Then
  36. 			strFilterKB = Mid( strFilterKB, 3 )
  37. 		End If
  38. 	End If
  39. End With
  40. If blnFilterKB And Not IsNumeric( strFilterKB ) Then Syntax
  41.  
  42. ' Create a Windows Update Searcher object
  43. Set objSearcher = CreateObject( "Microsoft.Update.Searcher" )
  44.  
  45. ' Query the complete history
  46. With objSearcher
  47. 	Set colHistory = .QueryHistory( 0, .GetTotalHistoryCount - 1 )
  48. End With
  49.  
  50. ' Loop through the stored history, and format the results
  51. For Each objHistory In colHistory
  52. 	With objHistory
  53. 		strUpd = "Title       : " & .Title                          & vbCrLf _
  54. 		       & "Description : " & .Description                    & vbCrLf _
  55. 		       & "Update ID   : " & .UpdateIdentity.UpdateID        _
  56. 		       & ", Rev. "        & .UpdateIdentity.RevisionNumber  & vbCrLf _
  57. 		       & "Support URL : " & .SupportUrl                     & vbCrLf _
  58. 		       & "Date        : " & .Date                           & vbCrLf _
  59. 		       & "Result      : " & arrOperations( .Operation )     _
  60. 		       & " "              & arrResultCodes( .ResultCode )   & vbCrLf & vbCrLf
  61. 		If blnFilterKB Then
  62. 			If InStr( 1, .Title, "KB" & strFilterKB, vbTextCompare ) Then
  63. 				strMsg = strMsg & strUpd
  64. 			End If
  65. 		Else
  66. 			strMsg = strMsg & strUpd
  67. 		End If
  68. 	End With
  69. Next
  70.  
  71. ' Display the end result
  72. WScript.Echo strMsg
  73.  
  74. ' Done
  75. Set colHistory  = Nothing
  76. Set objSearcher = Nothing
  77.  
  78.  
  79. Sub Syntax
  80. 	strMsg = vbCrLf _
  81. 	       & WScript.ScriptName & ",  Version 1.00" _
  82. 	       & vbCrLf _
  83. 	       & "List or query Windows Update history" _
  84. 	       & vbCrLf & vbCrLf _
  85. 	       & "Usage:  " & UCase( WScript.ScriptName ) & "  [ KBnumber | /KB:number ]" _
  86. 	       & vbCrLf & vbCrLf _
  87. 	       & "Where:  ""(KB)number""  is the Microsoft Knowledge Base number you want to" _
  88. 	       & vbCrLf _
  89. 	       & "                      query for (default is to list the complete history)" _
  90. 	       & vbCrLf & vbCrLf _
  91. 	       & "Written by Rob van der Woude" _
  92. 	       & vbCrLf _
  93. 	       & "http://www.robvanderwoude.com"
  94. 	WScript.Echo strMsg
  95. 	WScript.Quit 1
  96. End Sub
  97.  

page last modified: 2024-04-16; loaded in 0.0088 seconds