Vb.net Windows Update-希望使用联机而不是WSUS
我正在尝试调整此代码,以便它强制Windows Update搜索从Microsoft而不是本地WSUS服务器进行在线检查。如果我在公司网络之外运行该代码,则该代码可以正常工作,但我希望从公司网络运行并绕过WSUS服务器Vb.net Windows Update-希望使用联机而不是WSUS,vb.net,wuapi,Vb.net,Wuapi,我正在尝试调整此代码,以便它强制Windows Update搜索从Microsoft而不是本地WSUS服务器进行在线检查。如果我在公司网络之外运行该代码,则该代码可以正常工作,但我希望从公司网络运行并绕过WSUS服务器 Private Sub CheckForUpdates() Dim objUpdateSession As WUApiLib.UpdateSession Dim objUpdateSearcher As WUApiLib.UpdateSearcher
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
这是由
UseWUServer
在客户端注册表项上
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU
searchResult=updatesarcher.search(…)
这有点不太正常,但这是我找到的唯一方法。计算机中当前设置的组策略?不是这样,因为我可以从控制面板运行Windows Update,并选择直接转到MS的选项。我只是想知道如何通过API执行此操作