I am trying to adjust this code so it forces the Windows Update search to check online from Microsoft rather than the local WSUS server. This code works fine if I run it when I am outside my company network, but I want to run from the company network and bypass the WSUS server.
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