Need help converting WMI System.Management code in VB.NET

I am trying to get a LIST of applications from a specific PC' sregistry.  I have code pieced from other snippets and I feel I am pretty close; however, I am still gettng an error.  I use a single FORM and TEXTBOX to spit out the results.  I keep gettign this ERROR:  File name or class name not found during Automation operation.

Imports System.Management
Public Function InstalledApps() As String
        Dim strPcName As String = ""
        Dim strRegValue As Object
        Dim strKey As Object
        Dim intRegTest As Object
        Dim strBaseKey As Object
        Dim strValue As Object
        Dim arSubKeys()
        Dim iErr As Object
        Dim objWMIService As System.Management.ManagementObject
        Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
        objWMIService = GetObject("winmgmts:\\" & strPcName, "Root\CIMV2")
        strRegValue = GetObject("winmgmts://" & strPcName & "/root/default:StdRegProv")
        strBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
        intRegTest = strRegValue.EnumKey(HKLM, strBaseKey, arSubKeys)
        For Each strKey In arSubKeys
            intRegTest = strRegValue.GetStringValue(HKLM, strBaseKey & strKey, "DisplayName", strValue)
            If intRegTest <> 0 Then
                strRegValue.GetStringValue(HKLM, strBaseKey & strKey, "QuietDisplayName", strValue)
            End If
            If strValue <> "" Then
                InstalledApps = InstalledApps & strValue & ","
            End If
        TextBox1.Text = InstalledApps
    End Function

Open in new window

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

grayeConnect With a Mentor Commented:
If you're doing this from VB.Net, I'd suggest that you use the "native" registry class (rather than WMI's registry routines).
            Dim reg_hklm, key, subkey As RegistryKey  
            reg_hklm = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, RemotePC)
            key = reg_hklm.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall", False)
            If Not IsNothing(key) Then
                For Each temp In key.GetSubKeyNames()
                    subkey = key.OpenSubKey(temp, False)
                    If Not IsNothing(subkey.GetValue("DisplayName")) Then
                    End If
            End If

Open in new window

afsanchez001Author Commented:
Thanks graye!  I'll give it a try and report back to you.  -Anthony
afsanchez001Author Commented:
Worked like a charm, THANKS!!!
All Courses

From novice to tech pro — start learning today.