0

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
Mike
  • 33
  • 8
  • 1
    What does the C# look like? I doubt it uses CreateObject, and it would certainly have actual type names for each of these variables. Knowing that info here will certainly help us give you a better translation. – Joel Coehoorn Jun 10 '22 at 13:45
  • Also, it's probably worth reading this answer: https://stackoverflow.com/a/59165176/3043 – Joel Coehoorn Jun 10 '22 at 13:54
  • Another issue: are you **sure** it just hangs? `objSearcher.Search()` will actually run a full Windows Update check, including looking online through the MS catalog for new updates that might apply to this machine. This can take several minutes. – Joel Coehoorn Jun 10 '22 at 13:55
  • Finally, the KB3033929 update here applies to Windows 7, and Windows 7 is fully end of life. This means it no longer receives **any** new updates... not even critical security patches. _There are now several known, unpatched, and actively-exploited vulnerabilities in the wild_. It's dangerous and irresponsible to still be using this old OS. – Joel Coehoorn Jun 10 '22 at 14:02
  • These are offline kiosk computers running Windows 7 which cannot be changed. Do you have any suggestion to getting my code to work given that info? – Mike Jun 10 '22 at 14:39
  • Not unless you can post the C# version as requested. Given the age of the OS,, we also need to know what versions of the .Net framework are available. – Joel Coehoorn Jun 10 '22 at 15:31
  • Windows 7 (Version 6.1 build 7601 SP1) with .NET 2.0 – Mike Jun 10 '22 at 16:47

1 Answers1

0

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
Mike
  • 33
  • 8