I have a vb-script which checks if there are updates pending. Sometimes windows search returns an error (for example 503) and an error popup is generated. Since I'm not familiar with vbs, I don't know where to start searching for a solution.
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
The problem occurs in line 3. It says:
Script: C:\path-to-my-script\my-script.vbs Line: 3 Char: 1 Error: 0x80244022 Code: 80244022 Source: (null)
How can I either prevent the popup from being generated or get a handle to it and close it immediately?
Error 0x80244022 means that the update server HTTP service became temporarily unavailable (for whatever reason). See this MSKB article for a list of connectivity-related error codes.
To handle this error put it between an On Error Resume Next
and an On Error Goto 0
statement:
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
Note that the above will indiscriminately terminate the script on any error that occurs when calling the Search
method. If you want to handle different errors in different ways, you could for instance put a Select
statement inside the conditional:
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
User contributions licensed under CC BY-SA 3.0