DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Excel VBA : Read Registry Key Values On A Remote Computer Using WMI

  • submit to reddit
        // VBA code to paste in an module
Function ORACLEHOMES(strComputer As String)
    Const HKEY_LOCAL_MACHINE = &H80000002
    Dim strKeyPath
    Dim arrSubKeys
    Dim oReg
    Dim strValueName
    Dim strValue
    'strComputer = "."
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    strKeyPath = "SOFTWARE\ORACLE"
    oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
    For Each subkey In arrSubKeys
        If Left(subkey, 4) = "KEY_" Then
            strValueName = "ORACLE_HOME"
            oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey, strValueName, strValue
            If ORACLEHOMES = "" Then
                ORACLEHOMES = strValue
                ORACLEHOMES = ORACLEHOMES & ";" & strValue
            End If
        End If
End Function