Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for hotfixes.vbs

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

  1. ' Check command line parameters
  2. Select Case WScript.Arguments.Count
  3. 	Case 0
  4. 		' Default if none specified is local computer (".")
  5. 		Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
  6. 		Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
  7. 		For Each objItem in colItems
  8. 			strComputer = objItem.Name
  9. 		Next
  10. 	Case 1
  11. 		' Command line parameter can either be a computer name
  12. 		' or "/?" to request online help
  13. 		strComputer = Wscript.Arguments(0)
  14. 		if InStr( strComputer, "?" ) > 0 Then Syntax
  15. 	Case Else
  16. 		' Maximum is 1 command line parameter
  17. 		Syntax
  18. End Select
  19.  
  20. ' Header line for screen output
  21. strMsg = vbCrLf & "Hotfixes installed on " & strComputer & ":" & vbCrLf & vbCrLf
  22.  
  23. ' Enable error handling
  24. On Error Resume Next
  25.  
  26. ' Connect to specified computer
  27. Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2" )
  28. ' Display error number and description if applicable
  29. If Err Then ShowError
  30.  
  31. ' Query hotfixes
  32. Set colQuickFixes = objWMIService.ExecQuery( "Select * from Win32_QuickFixEngineering" )
  33. ' Display error number and description if applicable
  34. If Err Then ShowError
  35.  
  36. ' Prepare display of results
  37. For Each objQuickFix in colQuickFixes
  38. 	strMsg = strMsg _
  39. 	       & "    Description:       " _
  40. 	       & objQuickFix.Description & vbCrLf _
  41. 	       & "    Hot Fix ID:        " _
  42. 	       & objQuickFix.HotFixID & vbCrLf _
  43. 	       & "    Installation Date: " _
  44. 	       & objQuickFix.InstallDate & vbCrLf _
  45. 	       & "    Installed By:      " _
  46. 	       & objQuickFix.InstalledBy & vbCrLf & vbCrLf
  47. Next
  48.  
  49. ' Display results
  50. WScript.Echo strMsg
  51.  
  52. 'Done
  53. WScript.Quit(0)
  54.  
  55.  
  56. Sub ShowError()
  57. 	strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
  58. 	         Err.Description & vbCrLf & vbCrLf
  59. 	Syntax
  60. End Sub
  61.  
  62.  
  63. Sub Syntax()
  64. 	strMsg = strMsg & vbCrLf _
  65. 	       & "HotFixes.vbs,  Version 1.00" & vbCrLf _
  66. 	       & "List installed hotfixes for any computer on the network" _
  67. 	       & vbCrLf & vbCrLf _
  68. 	       & "Usage:  CSCRIPT  //NOLOGO  HOTFIXES.VBS  [ computer_name ]" _
  69. 	       & vbCrLf & vbCrLf _
  70. 	       & "Where:  " & Chr(34) & "computer_name" & Chr(34) _
  71. 	       & " is the optional name of a remote computer" & vbCrLf _
  72. 	       & "                        (default is local computer name)" _
  73. 	       & vbCrLf & vbCrLf _
  74. 	       & "Based entirely on Microsoft TechNet Script " _
  75. 	       & "Center's sample script:" & vbCrLf _
  76. 	       & "http://www.microsoft.com/technet/treeview/default.asp?" _
  77. 	       & "url=/technet/scriptcenter/compmgmt/ScrCM15.asp" _
  78. 	       & vbCrLf & vbCrLf _
  79. 	       & "Modified by Rob van der Woude" & vbCrLf _
  80. 	       & "http://www.robvanderwoude.com"
  81. 	WScript.Echo strMsg
  82. 	WScript.Quit(1)
  83. End Sub
  84.  

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