まりふのひと

Windows Updateの更新履歴をExcelで見るマクロを作成したが...

10/5 のブログ「Windows Updateで KB2552343 が失敗したまま...(未解決)」関連記事を調べている過程で、MSN 相談箱の「更新履歴の表示を検索することはできますか?」を見つけた。

 Windows Update 更新履歴のテキストファイルは
C:\Windows\SoftwareDistribution\ReportingEvents.log
にありますので、メモ帳で開いて検索することができます。
ご質問の例では、ms12-060 で検索するより、KBxxxxx で検索した方がいいと思います。

 更新履歴表示は、確かにいっぱいありますが、失敗した日と、KB番号を頼りに見ていけば見つけやすいと思います。


「しめたッ!」、早速 TeraPad で開いてみたら、Tab で切られたテキスト形式であることが解った。Excel マクロを作ろう‥‥


 ReportingEvents.log

  更新履歴の表示 ReportingEvents.log 備考
件数
700件弱
1114件
 
インストール日
2012/09/17

2013/10/05
2013/05/10

2013/10/06
logにインストール日に合わせると
更新履歴は 300件強になる。
「状態」の種類
成功
失敗
Success
Failure
 
「重要度」の種類
重要
推奨
オプション
「重要度」に相当する列を見つけ
られない...(下記参照)
 
※「重要度」に相当する I 列と K 列の組み合わせ

列(I)小計列(K)件数
AutomaticUpdates694Content Download151
  Content Install388
  Software Synchronization155
AutomaticUpdatesWuApp24Content Download24
ChkWuDrv16Content Download1
  Software Synchronization15
EAIME29Content Download3
  Content Install3
  Software Synchronization23
Microsoft Security Essentials341Content Download113
  Content Install114
  Software Synchronization114
Office365DesktopSetup10Content Download1
  Content Install2
  Software Synchronization7
総計1114 1114


 今日の結論

  1. ReportingEvents.log は更新履歴に代わるものではなかった。
    • インストール日の範囲が短い。
       逆に言えば、この程度の期間内にチェックしなさい‥‥ と、言っているのかも知れない。
    • 更新履歴以上の情報がある。
  2. 折角マクロまで作ったので、機あるごとに併用するとする。
     コードとしては綺麗でないが...
  3. 結果としては中途半端に終わった。


 マクロ(VBA)抜粋
後日の参考にするために載せた。

    • マクロの修整は殆ど行っていない。特に、Tab区切りテキストデータを取り込むところは...
    • ブログ上で付け加えたコメントもある。
  1. Option Explicit
  2.  
  3. Public Sub Auto_Open()
  4. On Error GoTo Err_Auto_Open
  5. Dim mbTitle As String
  6. Dim macBookName As String, macBookPath As String, newBookName As String
  7. 'Dim nameBookPath As Variant, nameBookName As String
  8. Dim i As Long, k As Long, SheetCTR As Long
  9. Dim lastCol As Long, lastRow As Long
  10. Dim strString As String
  11. 'Dim VARAns As Variant
  12.  
  13. mbTitle = "Auto_Open/" & ThisWorkbook.Name
  14. macBookName = ThisWorkbook.Name
  15. macBookPath = ThisWorkbook.Path
  16. '新規ブックを開く
  17. Workbooks.Add
  18. newBookName = ActiveWorkbook.Name
  19. 'Sheet2 以降は削除する。
  20. SheetCTR = Sheets.Count
  21. Application.DisplayAlerts = False    '警告を出さない。
  22. If SheetCTR > 1 Then
  23. For i = SheetCTR To 2 Step -1
  24. Sheets(i).Delete
  25. Next
  26. End If
  27. Application.DisplayAlerts = True
  28. 'ReportingEvents.log を取り込む
  29. With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\Windows\SoftwareDistribution\ReportingEvents.log" _
  30. , Destination:=Range("$A$1"))
  31. .Name = "ReportingEvents"
  32. .FieldNames = True
  33. .RowNumbers = False
  34. .FillAdjacentFormulas = False
  35. .PreserveFormatting = True
  36. .RefreshOnFileOpen = False
  37. .RefreshStyle = xlInsertDeleteCells
  38. .SavePassword = False
  39. .SaveData = True
  40. .AdjustColumnWidth = True
  41. .RefreshPeriod = 0
  42. .TextFilePromptOnRefresh = False
  43. .TextFilePlatform = 932
  44. .TextFileStartRow = 1
  45. .TextFileParseType = xlDelimited
  46. .TextFileTextQualifier = xlTextQualifierDoubleQuote
  47. .TextFileConsecutiveDelimiter = False
  48. .TextFileTabDelimiter = True
  49. .TextFileSemicolonDelimiter = False
  50. .TextFileCommaDelimiter = False
  51. .TextFileSpaceDelimiter = False
  52. '    .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
  53. .TextFileTrailingMinusNumbers = True
  54. .Refresh BackgroundQuery:=False
  55. End With
  56. '右下のアドレス
  57. Range("A1").Select
  58. ActiveCell.SpecialCells(xlLastCell).Select
  59. lastCol = ActiveCell.Column
  60. lastRow = ActiveCell.Row
  61. '1行目が空か調べる。
  62. For i = 1 To lastCol
  63. If Cells(1, i) <> "" Then Stop
  64. Next
  65. '項目名を付ける。
  66. Range("A1") = "列(A)"
  67. Range("B1") = "インストール日"
  68. Range("C1") = "列(C)"
  69. Range("D1") = "列(D)"
  70. Range("E1") = "列(E)"
  71. Range("F1") = "列(F)"
  72. Range("G1") = "列(G)"
  73. Range("H1") = "列(H)"
  74. Range("I1") = "列(I)"
  75. Range("J1") = "状態"
  76. Range("K1") = "重要度"
  77. Range("L1") = "名前"
  78. 'B列を日付型に変更する。
  79. For i = 2 To lastRow
  80. strString = Cells(i, 2)
  81. k = InStrRev(strString, ":")
  82. If k = 20 Then Cells(i, 2) = Left(strString, 19)
  83. Next
  84. 'B列の書式設定
  85. Columns("B:B").Select
  86. Selection.NumberFormatLocal = "yyyy/mm/dd"
  87. '中央揃え
  88. Columns("B:B").Select
  89. With Selection
  90. .HorizontalAlignment = xlCenter
  91. .VerticalAlignment = xlCenter
  92. .WrapText = False
  93. End With
  94. Range("A1:L1").Select
  95. With Selection
  96. .HorizontalAlignment = xlCenter
  97. .VerticalAlignment = xlCenter
  98. .WrapText = False
  99. End With
  100. 'B列を最適幅にする。
  101. Columns("B:B").EntireColumn.AutoFit
  102. '項目行を塗りつぶし、格子線を引く。
  103. Range("A1:L1").Select
  104. With Selection.Interior
  105. .Pattern = xlSolid
  106. .PatternColorIndex = xlAutomatic
  107. .ThemeColor = xlThemeColorAccent5
  108. .TintAndShade = 0.799981688894314
  109. .PatternTintAndShade = 0
  110. End With
  111. Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  112. Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  113. With Selection.Borders(xlEdgeLeft)
  114. .LineStyle = xlContinuous
  115. .ColorIndex = 0
  116. .TintAndShade = 0
  117. .Weight = xlThin
  118. End With
  119. With Selection.Borders(xlEdgeTop)
  120. .LineStyle = xlContinuous
  121. .ColorIndex = 0
  122. .TintAndShade = 0
  123. .Weight = xlThin
  124. End With
  125. With Selection.Borders(xlEdgeBottom)
  126. .LineStyle = xlContinuous
  127. .ColorIndex = 0
  128. .TintAndShade = 0
  129. .Weight = xlThin
  130. End With
  131. With Selection.Borders(xlEdgeRight)
  132. .LineStyle = xlContinuous
  133. .ColorIndex = 0
  134. .TintAndShade = 0
  135. .Weight = xlThin
  136. End With
  137. With Selection.Borders(xlInsideVertical)
  138. .LineStyle = xlContinuous
  139. .ColorIndex = 0
  140. .TintAndShade = 0
  141. .Weight = xlThin
  142. End With
  143. With Selection.Borders(xlInsideHorizontal)
  144. .LineStyle = xlContinuous
  145. .ColorIndex = 0
  146. .TintAndShade = 0
  147. .Weight = xlThin
  148. End With
  149. 'ウィンドウ枠の固定
  150. Range("C2").Select
  151. ActiveWindow.FreezePanes = True
  152. '列を非表示にする。
  153. Range("A1").Select
  154. Columns("A:A").Select
  155. Selection.EntireColumn.Hidden = True
  156. Columns("C:H").Select
  157. Selection.EntireColumn.Hidden = True
  158. 'Ctrl+Home
  159. Range("I2").Select
  160.  
  161. Exit_Auto_Open:
  162. Exit Sub
  163.  
  164. Err_Auto_Open:
  165. MsgBox Err.Number & "/" & Err.Description, vbCritical, mbTitle
  166. Resume Exit_Auto_Open
  167. End Sub
  168.  
  169. Public Sub 再表示する()
  170.  
  171. Columns("A:L").Select
  172. Selection.EntireColumn.Hidden = False
  173. Range("A1").Select
  174.  
  175. End Sub