我正在尝试调整此代码,使其强制 Windows 更新搜索从 Microsoft 而不是本地 WSUS 服务器在线检查。如果我在公司网络之外运行此代码,它可以正常工作,但我想从公司网络运行并绕过 WSUS 服务器。
Private Sub CheckForUpdates()
Dim objUpdateSession As WUApiLib.UpdateSession
Dim objUpdateSearcher As WUApiLib.UpdateSearcher
Dim objSearchResults As WUApiLib.ISearchResult
Dim objUpdateDownloader As WUApiLib.UpdateDownloader
Dim NowInstallThem As WUApiLib.UpdateInstaller
Dim NumPatches As Integer = -1
Dim Updates As New WUApiLib.UpdateCollection
Try
objUpdateSession = New WUApiLib.UpdateSession
objUpdateSearcher = objUpdateSession.CreateUpdateSearcher()
objSearchResults = objUpdateSearcher.Search("IsInstalled=0 and Type='Software'")
NumPatches = objSearchResults.Updates.Count
MessageBox.Show("Number of patches: " & NumPatches.ToString)
Dim patch As WUApiLib.IUpdate
For a = 0 To NumPatches - 1
patch = objSearchResults.Updates.Item(a)
Updates.Add(patch)
Next
If NumPatches > 0 Then
objUpdateDownloader.Updates = Updates
objUpdateDownloader.Download()
MessageBox.Show("patches downloaded")
NowInstallThem.Updates = Updates
NowInstallThem.Install()
MessageBox.Show("patches installed")
End If
Catch ex As Exception
End Try
End Sub