我正在尝试调整此代码,因此它强制Windows Update搜索从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
答案 0 :(得分:0)
这是由管理
UseWUServer
在客户端注册表项上
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU
searchResult = updateSearcher.Search(...)
如果键或值不存在,则它已经使用了 Microsoft 更新服务器。
这有点老套,但我找到的唯一方法。