Option Explicit
Sub ListWindowsUpdates()
Dim objUpdateSession As Object
Dim intTotalHistoryCount As Integer
Dim objUpdateEntry As Object
Dim objUpdateIdentity As Object
Dim intRowNumber As Integer
Dim objUpdateSearcher As Object
Dim updateHistory
intRowNumber = 7
Set objUpdateSession = CreateObject("Microsoft.Update.Session")
Set objUpdateSearcher = objUpdateSession.CreateUpdateSearcher
intTotalHistoryCount = objUpdateSearcher.GetTotalHistoryCount
Set updateHistory = objUpdateSearcher.QueryHistory(0, intTotalHistoryCount)
For Each objUpdateEntry In updateHistory
Cells(intRowNumber, 1) = objUpdateEntry.Title
Cells(intRowNumber, 2) = objUpdateEntry.Description
Cells(intRowNumber, 3) = objUpdateEntry.Date
Select Case objUpdateEntry.Operation
Case 1
Cells(intRowNumber, 4) = "Installation"
Case 2
Cells(intRowNumber, 4) = "Uninstallation"
Case Else
Cells(intRowNumber, 4) = "Operation type could not be determined."
End Select
Select Case objUpdateEntry.ResultCode
Case 0
Cells(intRowNumber, 5) = "Operation has not started."
Case 1
Cells(intRowNumber, 5) = "Operation is in progress."
Case 2
Cells(intRowNumber, 5) = "Operation completed successfully."
Case 3
Cells(intRowNumber, 5) = "Operation completed, but one or more errors occurred " & _
"during the operation and the results are potentially incomplete."
Case 4
Cells(intRowNumber, 5) = "Operation failed to complete."
Case 5
Cells(intRowNumber, 5) = "Operation was aborted."
Case Else
Cells(intRowNumber, 5) = "Operation result could not be determined."
End Select
Set objUpdateIdentity = objUpdateEntry.UpdateIdentity
Cells(intRowNumber, 6) = objUpdateIdentity.UpdateID
intRowNumber = intRowNumber + 1
Next
Range("A6").Select
ActiveCell.FormulaR1C1 = "Title:"
Range("B6").Select
ActiveCell.FormulaR1C1 = "Description:"
Range("C6").Select
ActiveCell.FormulaR1C1 = "Update Application Date:"
Range("D6").Select
ActiveCell.FormulaR1C1 = "Operation Type:"
Range("E6").Select
ActiveCell.FormulaR1C1 = "Operation Result:"
Range("F6").Select
ActiveCell.FormulaR1C1 = "Update ID:"
Range("A6:F6").Select
Selection.Font.Bold = True
Columns("A:A").EntireColumn.AutoFit
Columns("B:B").EntireColumn.AutoFit
Columns("C:C").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit
Columns("E:E").EntireColumn.AutoFit
Columns("F:F").EntireColumn.AutoFit
Columns("B:B").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Selection.ColumnWidth = 85
Rows("7:7").Select
ActiveWindow.FreezePanes = True
Range("A1").Select
Set objUpdateSession = Nothing
Set objUpdateEntry = Nothing
Set objUpdateIdentity = Nothing
Set objUpdateSearcher = Nothing
Set updateHistory = Nothing
End Sub
|