' NAME: WindowsUpdateHistory.vbs ' ' AUTHOR: Alan dot Kaplan at VA dot gov ' DATE : 8/14/2006, 5/1/2010 ' ' COMMENT: based on code at found at ' http://www.microsoft.com/technet/scriptcenter/resources/tales/sg0705.mspx ' '========================================================================== Option Explicit Dim WshShell Set WshShell = WScript.CreateObject("WScript.Shell") Dim strComputer dim objSession , objSearcher, colHistory, objEntry Dim iHC, intHistoryDisplay Dim message If WScript.Arguments.Count = 1 Then strComputer = WScript.Arguments(0) Else strComputer = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%") strComputer = InputBox("Get Windows Update History from what computer","PC Name",strComputer) End If If strcomputer = "" Then WScript.Quit strComputer = UCase(strComputer) On Error Resume next Set objSession = CreateObject("Microsoft.Update.Session", strComputer) If Err <> 0 Then MsgBox Err.Description,vbCritical + vbOKOnly,strComputer & " Error" WScript.Quit End If Set objSearcher = objSession.CreateUpdateSearcher iHC = objSearcher.GetTotalHistoryCount intHistoryDisplay = InputBox(iHC & " updates found. Display information about how many of these?","Display Limit",iHC) intHistoryDisplay = CInt(intHistoryDisplay) if intHistoryDisplay = 0 Then MsgBox "User cancelled, or no History found." ,vbCritical + vbOKOnly,strComputer & " Error" WScript.Quit End If Message = iHC & " updates found, displaying " & intHistoryDisplay & VbCrLf If intHistoryDisplay > iHC Then intHistoryDisplay = iHC ' max If intHistoryDisplay < 1 Then WScript.Quit If intHistoryDisplay = "" Then WScript.Quit dim i: i = 0 Set colHistory = objSearcher.QueryHistory(0, intHistoryDisplay) For Each objEntry in colHistory If i > intHistoryDisplay Then Exit For Select Case objEntry.Operation Case 1 Message = Message & vbNewLine & objEntry.Title & " (Installation)" Case 2 Message = Message & vbNewLine & objEntry.Title& " (Uninstall)" Case Else Message = Message & vbNewLine & objEntry.Title & " (Type could not be determined)" End Select Message = Message & vbNewLine & "Description: " & objEntry.Description Message = Message & vbNewLine & "Date: " & objEntry.Date Select Case objEntry.ResultCode Case 0 Message = Message & vbNewLine & "Result: Has not started." Case 1 Message = Message & vbNewLine & "Result: In progress." Case 2 Message = Message & vbNewLine & "Result: Completed successfully." Case 3 Message = Message & vbNewLine & "Result: Completed, but one or more errors occurred " & _ "during the and the Results are potentially incomplete." Case 4 Message = Message & vbNewLine & "Result: Failed to complete." Case 5 Message = Message & vbNewLine & "Result: Aborted." Case Else Message = Message & vbNewLine & "The result could not be determined." End Select message = Message & vbNewLine & vbNewLine i = i + 1 Next IEMessage message,"Windows Update Patch History for " & strComputer,"lt Blue",800,800,True '================ Functions and Subs ============== Sub IEMessage(message,strTitle,strBGColor,iHeight,IWidth,bPrint) Dim oIE, oPage Dim strComputer, strBorder, strFont Dim strFormatOn, strFormatOff, iTSView Set oIE = CreateObject("InternetExplorer.Application") iTSview = 1 ' to allow print, find and saveAs. Print dialog easy, find not so much strBorder = 1 'Best appearance is strBorder 1 strFont = "Arial" oIE.Navigate "about:blank" oIE.AddressBar = False oIE.Height = iHeight oIE.Width = IWidth oIE.MenuBar = iTSView oIE.ToolBar = iTSView oIE.StatusBar = False oIE.Left = 10 oIE.Top = 10 oIE.Visible = 1 message = Replace(message,vbcrlf,"
"& vbcrlf) Do While (oIE.Busy) Wscript.Sleep 250 Loop Set oPage = oIE.Document oPage.Open oPage.Writeln "" & strTitle & "" oPage.Writeln "" oPage.Writeln "" oPage.Writeln "

" & strTitle & "

" oPage.Writeln "" & Message & "
" oPage.Writeln "
" oPage.Write() oPage.Close End Sub