强制Windows Update使用过滤器检查更新,以避免某些类型的更新?


0

我需要创建一个程序来检查并安装重要更新

是否只有更新可用时才创建弹出窗口?

目前,我正在使用以下代码检查更新:

' Written in 2007 by Harry Johnston, University of Waikato, New Zealand.
' This code has been placed in the public domain.  It may be freely
' used, modified, and distributed.  However it is provided with no
' warranty, either express or implied.
'
' Exit Codes:
'   0 = scripting failure
'   1 = error obtaining or installing updates
'   2 = installation successful, no further updates to install
'   3 = reboot needed; rerun script after reboot
'
' Note that exit code 0 has to indicate failure because that is what
' is returned if a scripting error is raised.
'

Set updateSession = CreateObject("Microsoft.Update.Session")

Set updateSearcher = updateSession.CreateUpdateSearcher()
Set updateDownloader = updateSession.CreateUpdateDownloader()
Set updateInstaller = updateSession.CreateUpdateInstaller()

Do

  WScript.Echo
  WScript.Echo "Searching for approved updates ..."
  WScript.Echo

  Set updateSearch = updateSearcher.Search("IsInstalled=0")

  If updateSearch.ResultCode <> 2 Then

    WScript.Echo "Search failed with result code", updateSearch.ResultCode
    WScript.Quit 1

  End If

  If updateSearch.Updates.Count = 0 Then

    WScript.Echo "There are no updates to install."
    WScript.Quit 2

  End If

  Set updateList = updateSearch.Updates

  For I = 0 to updateSearch.Updates.Count - 1

    Set update = updateList.Item(I)

    WScript.Echo "Update found:", update.Title

  Next

  WScript.Echo

  updateDownloader.Updates = updateList
  updateDownloader.Priority = 3

  Set downloadResult = updateDownloader.Download()

  If downloadResult.ResultCode <> 2 Then

    WScript.Echo "Download failed with result code", downloadResult.ResultCode
    WScript.Echo

    WScript.Quit 1

  End If

  WScript.Echo "Download complete.  Installing updates ..."
  WScript.Echo

  updateInstaller.Updates = updateList

  Set installationResult = updateInstaller.Install()

  If installationResult.ResultCode <> 2 Then

    WScript.Echo "Installation failed with result code", installationResult.ResultCode

    For I = 0 to updateList.Count - 1

      Set updateInstallationResult = installationResult.GetUpdateResult(I)
      WScript.Echo "Result for " & updateList.Item(I).Title & " is " & installationResult.GetUpdateResult(I).ResultCode

    Next

    WScript.Quit 1

  End If

  If installationResult.RebootRequired Then

    WScript.Echo "The system must be rebooted to complete installation."

    WScript.Quit 3

  End If

  WScript.Echo "Installation complete."

Loop

Answers:


0

Windows Update API功能非常强大,但是要确定哪个更新实际上是“重要的”并不容易-您的代码显示了一个非常简单的搜索,可以搜索尚未安装的所有更新。您可以列出更新程序包并查询IUpdate接口的属性(请参阅http://msdn.microsoft.com/zh-cn/library/windows/desktop/aa386099(v=vs.85).aspx

您也可以看一下WuInstall(以前有一个免费版本,但他们将其发布在网站上,现在只有带有免费试用版的商业版本才可用)-它还在命令中利用了Windows Update API线工具。请参阅http://www.wuinstall.com/http://help.wuinstall.com/en/index.html

基本上,您可以执行WuInstall可以使用Windows Update API进行的许多(不是全部)操作,但是它可以节省大量的编程和调试时间。

顺便说一句,“创建弹出窗口”是什么意思?


它创建了多个窗口,以通知用户任何可用的更新。上面的代码可以正常工作,但是要想获得所有更新,您必须通过单击...来更新窗口...不需要100多个更新。
CS_STEM 2014年

如果您使用此VBScript [link](superuser.com/questions/1152177/…),则只有在更新可用时弹出的消息框。
马修·威
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.