I want to check for a specific Windows Security Update in my WinForm running on an offline standalone Win7 Kiosk Machine. I think I have an infinite loop cause it just hangs when I run this code. I can't seem to find my issue. I found similar code in C# and tried to convert it to VB.NET but maybe I didn't do it correctly.
I basically just want to check the system for KB3033929 and then if it is installed, hide a button and show a label.
' ***** CHECK FOR PATCH *****
Dim objSession = CreateObject("Microsoft.Update.Session")
Dim objSearcher = objSession.CreateUpdateSearcher
Dim objResults = objSearcher.Search("Type='Software'")
Dim colUpdates = objResults.Updates
For i = 0 To colUpdates.Count - 1
If colUpdates.Item(i).Title = "Security Update for Windows (KB3033929)" Then
If colUpdates.Item(i).IsInstalled <> 0 Then
Label4.Visible = True
PatchInstall.Visible = False
End If
End If
Next
CodePudding user response:
Please correct me if I am wrong, but after more research I think this does what I need? I honestly am still trying to understand it, but after installing the patch I get the popup from the MsgBox with this code:
'***** CHECK FOR PATCH *****
Private Sub CheckPatch()
Dim ConOptions As New ConnectionOptions() With {.EnablePrivileges = True, .Timeout = EnumerationOptions.InfiniteTimeout}
Dim mOptions As New EnumerationOptions() With {.Rewindable = False, .ReturnImmediately = True, .DirectRead = True, .EnumerateDeep = False}
Dim mQuery As New SelectQuery("SELECT HotFixID FROM Win32_QuickFixEngineering WHERE HotFixID = 'KB3033929'")
Dim mScope As New ManagementScope($"\\{Environment.MachineName}\root\CIMV2", ConOptions)
mScope.Connect()
Using moSearcher As New ManagementObjectSearcher(mScope, mQuery, mOptions)
If moSearcher.Get().Count > 0 Then
MsgBox("Patch Installed!")
End If
End Using
End Sub