【问题标题】:Suppress popup window in vbs on timeout of Windows Update Search在 Windows 更新搜索超时时抑制 vbs 中的弹出窗口
【发布时间】:2013-10-16 19:03:41
【问题描述】:

我有一个 vb 脚本,用于检查是否有待处理的更新。有时 Windows 搜索会返回错误(例如 503)并生成错误弹出窗口。由于我对vbs不熟悉,所以不知道从哪里开始寻找解决方案。


        Set updateSession = CreateObject("Microsoft.Update.Session")
        Set updateSearcher = updateSession.CreateupdateSearcher()
        Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")

问题出现在第 3 行。它说:

脚本:C:\path-to-my-script\my-script.vbs 线路:3 字符:1 错误:0x80244022 代码:80244022 来源:(空)

如何防止弹出窗口生成或获取它的句柄并立即关闭它?

【问题讨论】:

    标签: vbscript windows-update


    【解决方案1】:

    错误 0x80244022 表示更新服务器 HTTP 服务暂时不可用(无论出于何种原因)。有关连接相关的错误代码列表,请参阅 this MSKB article

    要处理此错误,请将其置于 On Error Resume NextOn Error Goto 0 语句之间:

    Set updateSession = CreateObject("Microsoft.Update.Session")
    Set updateSearcher = updateSession.CreateupdateSearcher()
    
    On Error Resume Next
    Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
    If Err Then
      'add logging routine here
      WScript.Quit 1
    End If
    On Error Goto 0
    
    'more code here
    

    请注意,在调用Search 方法时发生任何错误时,上述内容将不加选择地终止脚本。如果您想以不同的方式处理不同的错误,例如可以在条件语句中添加 Select 语句:

    If Err Then
      Select Case Err.Number
        Case &h80244022
          'quit immediately
          WScript.Quit 1
        Case &h8009033F
          'wait some time and retry
          WScript.Sleep 900000
          Set searchResult = updateSearcher.Search(...)
        Case &h...
          'just log a message and continue
          ...
      End Select
    End If
    

    【讨论】:

    • 谢谢,我知道错误的原因是什么,但由于我自己从未编写过 vbscript,我不知道如何处理它或从哪里开始搜索。非常感谢两位的指点,我会从那里着手。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    • 1970-01-01
    相关资源
    最近更新 更多