使用UpdateSearcher.Search时出现错误80070002

时间:2018-06-12 14:39:55

标签: vbscript msdn

我在官方MSDN网站上发现这个VBScript,使用wsusscn2.cab文件(https://msdn.microsoft.com/en-us/library/windows/desktop/aa387290(v=vs.85).aspx)离线检查更新。这是给出的代码:

Set UpdateSession = CreateObject("Microsoft.Update.Session")
Set UpdateServiceManager = CreateObject("Microsoft.Update.ServiceManager")
Set UpdateService = UpdateServiceManager.AddScanPackageService("Offline Sync Service", "C:\wsusscn2.cab", 1)
Set UpdateSearcher = UpdateSession.CreateUpdateSearcher()

WScript.Echo "Searching for updates..." & vbCRLF

UpdateSearcher.ServerSelection = 3 

UpdateSearcher.ServiceID = UpdateService.ServiceID

Set SearchResult = UpdateSearcher.Search("IsInstalled=0")

Set Updates = SearchResult.Updates

If searchResult.Updates.Count = 0 Then
    WScript.Echo "There are no applicable updates."
    WScript.Quit
End If

WScript.Echo "List of applicable items on the machine when using wssuscan.cab:" & vbCRLF

For I = 0 to searchResult.Updates.Count-1
    Set update = searchResult.Updates.Item(I)
    WScript.Echo I + 1 & "> " & update.Title
Next

WScript.Quit

执行代码时,我在第12行收到错误消息“系统无法找到指定的文件”。第12行

Set SearchResult = UpdateSearcher.Search("IsInstalled=0")

脚本放在带有wsusscn2.cab文件的C盘中。任何形式的帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您遇到Windows Update问题,这不是VBScript问题:

https://support.microsoft.com/en-us/help/4027322/windows-update-troubleshooter