{"id":8315,"date":"2017-04-13T09:37:36","date_gmt":"2017-04-13T00:37:36","guid":{"rendered":"https:\/\/www.ka-net.org\/blog\/?p=8315"},"modified":"2017-04-13T09:37:36","modified_gmt":"2017-04-13T00:37:36","slug":"windows-update%e3%81%ae%e6%9b%b4%e6%96%b0%e5%b1%a5%e6%ad%b4%e3%82%92csvutf-8%e3%81%a7%e4%bf%9d%e5%ad%98%e3%81%99%e3%82%8bvbscript","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=8315","title":{"rendered":"Windows Update\u306e\u66f4\u65b0\u5c65\u6b74\u3092CSV(UTF-8)\u3067\u4fdd\u5b58\u3059\u308bVBScript"},"content":{"rendered":"<p>\u4ee5\u524d\u66f8\u3044\u305f\u30b9\u30af\u30ea\u30d7\u30c8\u304c\u51fa\u3066\u304d\u307e\u3057\u305f\u3002<br \/>\nWindows Update\u306e\u66f4\u65b0\u5c65\u6b74\u3092<\/p>\n<p>&#8220;\u66f4\u65b0\u65e5\u6642&#8221;,&#8221;\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u540d&#8221;,&#8221;\u30e6\u30fc\u30b6\u30fc\u540d&#8221;,&#8221;\u30bf\u30a4\u30c8\u30eb&#8221;,&#8221;KB\u756a\u53f7&#8221;,&#8221;\u7d50\u679c&#8221;<\/p>\n<p>\u3068\u3044\u3063\u305f\u5f62\u5f0f\u306eCSV\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u51fa\u529b\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3059\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\nDim dir_path, cn, ymd\r\n\r\ndir_path = &quot;&quot; 'CSV\u30d5\u30a1\u30a4\u30eb\u306e\u51fa\u529b\u5148\u6307\u5b9a\r\n\r\nIf Len(Trim(dir_path)) &lt; 1 Then _\r\n   dir_path = CreateObject(&quot;Scripting.FileSystemObject&quot;).GetParentFolderName(WScript.ScriptFullName)\r\ndir_path = AddPathSeparator(dir_path)\r\n\r\ncn = CreateObject(&quot;WScript.Network&quot;).ComputerName\r\nymd = Year(Now()) &amp; Right(&quot;0&quot; &amp; Month(Now()), 2) &amp; Right(&quot;0&quot; &amp; Day(Now()), 2)\r\nOutputMSUpdateInfo dir_path &amp; ymd &amp; &quot;_MSUP_&quot; &amp; cn &amp; &quot;.csv&quot;\r\n\r\nPublic Sub OutputMSUpdateInfo(ByVal TxtFilePath)\r\n'Windows Update\u306e\u66f4\u65b0\u5c65\u6b74\u3092CSV(UTF-8)\u3067\u4fdd\u5b58\r\n  Dim str\r\n  Const adTypeText = 2\r\n  Const adSaveCreateOverWrite = 2\r\n  \r\n  str = GetMSUpdateInfo\r\n  If Len(Trim(str)) &gt; 0 Then\r\n    With CreateObject(&quot;ADODB.Stream&quot;)\r\n      .Type = adTypeText\r\n      .Charset = &quot;UTF-8&quot;\r\n      .Open\r\n      .WriteText str\r\n      .SaveToFile TxtFilePath, adSaveCreateOverWrite\r\n      .Close\r\n    End With\r\n  End If\r\nEnd Sub\r\n\r\nPrivate Function GetMSUpdateInfo()\r\n'Windows Update\u306e\u66f4\u65b0\u5c65\u6b74\u53d6\u5f97\r\n  Dim us 'WUApiLib.UpdateSession\r\n  Dim sr 'WUApiLib.UpdateSearcher\r\n  Dim uhec 'WUApiLib.IUpdateHistoryEntryCollection\r\n  Dim uhe 'WUApiLib.IUpdateHistoryEntry\r\n  Dim rs\r\n  Dim kb, rc\r\n  Dim cn, un\r\n  Dim cnt\r\n  Dim ret\r\n  Const adVarChar = 200\r\n  Const adDBTimeStamp = 135\r\n  \r\n  Set us = CreateObject(&quot;Microsoft.Update.Session&quot;)\r\n  Set sr = us.CreateUpdateSearcher\r\n  \r\n  cnt = sr.GetTotalHistoryCount\r\n  If cnt &lt; 1 Then Exit Function\r\n  \r\n  '\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u540d\u3068\u30e6\u30fc\u30b6\u30fc\u540d\u53d6\u5f97\r\n  With CreateObject(&quot;WScript.Network&quot;)\r\n    cn = .ComputerName\r\n    un = .UserName\r\n  End With\r\n  \r\n  '\u30ec\u30b3\u30fc\u30c9\u30bb\u30c3\u30c8\u8a2d\u5b9a\r\n  Set rs = CreateObject(&quot;ADODB.Recordset&quot;)\r\n  rs.Fields.Append &quot;Date&quot;, adDBTimeStamp, 255\r\n  rs.Fields.Append &quot;ComputerName&quot;, adVarChar, 255\r\n  rs.Fields.Append &quot;UserName&quot;, adVarChar, 255\r\n  rs.Fields.Append &quot;Title&quot;, adVarChar, 255\r\n  rs.Fields.Append &quot;KB&quot;, adVarChar, 255\r\n  rs.Fields.Append &quot;Result&quot;, adVarChar, 255\r\n  rs.Open\r\n  \r\n  Set uhec = sr.QueryHistory(0, cnt)\r\n  For Each uhe In uhec\r\n    kb = UCase(uhe.Title)\r\n    If InStr(kb, &quot;KB&quot;) Then\r\n      kb = Mid(kb, InStr(kb, &quot;KB&quot;))\r\n      kb = Left(kb, InStr(kb, &quot;)&quot;) - 1)\r\n    Else\r\n      kb = &quot;&quot;\r\n    End If\r\n    \r\n    'OperationResultCode enumeration\r\n    'https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa387095.aspx\r\n    Select Case uhe.ResultCode\r\n      Case 0: rc = &quot;NotStarted&quot;\r\n      Case 1: rc = &quot;InProgress&quot;\r\n      Case 2: rc = &quot;Succeeded&quot;\r\n      Case 3: rc = &quot;SucceededWithErrors&quot;\r\n      Case 4: rc = &quot;Failed&quot;\r\n      Case 5: rc = &quot;Aborted&quot;\r\n      Case Else: rc = &quot;&quot;\r\n    End Select\r\n    \r\n    rs.AddNew\r\n    rs.Fields(&quot;Date&quot;).Value = uhe.Date\r\n    rs.Fields(&quot;ComputerName&quot;).Value = cn\r\n    rs.Fields(&quot;UserName&quot;).Value = un\r\n    rs.Fields(&quot;Title&quot;).Value = uhe.Title\r\n    rs.Fields(&quot;KB&quot;).Value = kb\r\n    rs.Fields(&quot;Result&quot;).Value = rc\r\n    rs.Update\r\n  Next\r\n  rs.Sort = &quot;Date DESC&quot; '\u65e5\u4ed8\u3067\u964d\u9806\u30bd\u30fc\u30c8\r\n  rs.MoveFirst\r\n  Do Until rs.EOF\r\n    ret = ret &amp; _\r\n          ChrW(34) &amp; rs.Fields(&quot;Date&quot;).Value &amp; ChrW(34) &amp; ChrW(44) &amp; _\r\n          ChrW(34) &amp; rs.Fields(&quot;ComputerName&quot;).Value &amp; ChrW(34) &amp; ChrW(44) &amp; _\r\n          ChrW(34) &amp; rs.Fields(&quot;UserName&quot;).Value &amp; ChrW(34) &amp; ChrW(44) &amp; _\r\n          ChrW(34) &amp; rs.Fields(&quot;Title&quot;).Value &amp; ChrW(34) &amp; ChrW(44) &amp; _\r\n          ChrW(34) &amp; rs.Fields(&quot;KB&quot;).Value &amp; ChrW(34) &amp; ChrW(44) &amp; _\r\n          ChrW(34) &amp; rs.Fields(&quot;Result&quot;).Value &amp; ChrW(34) &amp; vbNewLine\r\n    rs.MoveNext\r\n  Loop\r\n  rs.Close\r\n  ret = Left(ret, InStrRev(ret, vbNewLine) - 1) '\u6700\u5f8c\u306e\u6539\u884c\u524a\u9664\r\n  GetMSUpdateInfo = ret\r\nEnd Function\r\n\r\nPrivate Function AddPathSeparator(ByVal s)\r\n  If Right(s, 1) &lt;&gt; ChrW(92) Then s = s &amp; ChrW(92)\r\n  AddPathSeparator = s\r\nEnd Function<\/pre>\n<p>\u591a\u6570\u306e\u7aef\u672b\u306eWindows Update\u5c65\u6b74\u3092\u3001\u4e00\u53f0\u4e00\u53f0\u78ba\u8a8d\u3059\u308b\u306e\u304c\u9762\u5012\u304f\u3055\u304b\u3063\u305f\u306e\u3067\u66f8\u3044\u305f\u3088\u3046\u306a\u8a18\u61b6\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>VBScript\u304b\u3089\u306eWindows Update\u306e\u53d6\u308a\u6271\u3044\u306b\u3064\u3044\u3066\u306f\u4e0b\u8a18Web\u30da\u30fc\u30b8\u306b\u8a73\u3057\u304f\u307e\u3068\u3081\u3089\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u8208\u5473\u304c\u3042\u308b\u65b9\u306f\u305d\u3061\u3089\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\u3002<\/p>\n<ul>\n<li>\u304a\u307e\u3048\u3068\u305d\u306e\u72ac\u306e\u547d\u306f\u306a\u3044\u304b\u3089\u306d&#8230;Windows Update \u3082\u7ba1\u7406\u3057\u307e\u3057\u3087\u3046<\/li>\n<li style=\"list-style-type:none;\"><a href=\"https:\/\/technet.microsoft.com\/ja-jp\/scriptcenter\/ff595215.aspx\" target=\"_blank\" title=\"\u304a\u307e\u3048\u3068\u305d\u306e\u72ac\u306e\u547d\u306f\u306a\u3044\u304b\u3089\u306d...Windows Update \u3082\u7ba1\u7406\u3057\u307e\u3057\u3087\u3046\">https:\/\/technet.microsoft.com\/ja-jp\/scriptcenter\/ff595215.aspx<\/a><\/li>\n<\/ul>\n<div id=\"single_banner_area2\" class=\"clearfix one_banner\">\n<div class=\"single_banner single_banner_left\">\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<!-- \u8a18\u4e8b\u4e2d(\u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u5e83\u544a\u30e6\u30cb\u30c3\u30c8) -->\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block\"\r\n     data-ad-client=\"ca-pub-7306936664602087\"\r\n     data-ad-slot=\"5429724765\"\r\n     data-ad-format=\"auto\"\r\n     data-full-width-responsive=\"true\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\n<\/div>\n<div class=\"single_banner single_banner_right\">\n<a href=\"\" target=\"_blank\"><img decoding=\"async\" src=\"\" alt=\"\" title=\"\" \/><\/a>\n<\/div>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"\u4ee5\u524d\u66f8\u3044\u305f\u30b9\u30af\u30ea\u30d7\u30c8\u304c\u51fa\u3066\u304d\u307e\u3057\u305f\u3002 Windows Update\u306e\u66f4\u65b0\u5c65\u6b74\u3092 &#8220;\u66f4\u65b0\u65e5\u6642&#8221;,&#8221;\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u540d&#8221;,&#8221;\u30e6\u30fc\u30b6\u30fc\u540d&#8221;,&#8221;\u30bf [&hellip;]","protected":false},"author":1,"featured_media":7132,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"\u7ba1\u7406\u3059\u308bWindows\u7aef\u672b\u304c\u591a\u3044\u5834\u5408\u306b\u306f\u4f7f\u3048\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002  [Windows Update\u306e\u66f4\u65b0\u5c65\u6b74\u3092CSV(UTF-8)\u3067\u4fdd\u5b58\u3059\u308bVBScript]","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6],"tags":[],"class_list":["post-8315","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vbs"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-VBScript.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-2a7","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/8315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8315"}],"version-history":[{"count":1,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/8315\/revisions"}],"predecessor-version":[{"id":8316,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/8315\/revisions\/8316"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7132"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}