Using RegQueryValueEx to Read Registry Information : Registry « Windows API « VBA / Excel / Access / Word






Using RegQueryValueEx to Read Registry Information

 
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Sub cmdRead()
    Dim strValue As String * 256
    Dim lngRetval As Long
    Dim lngLength As Long
    Dim lngKey As Long

    If RegOpenKeyEx(HKEY_CURRENT_USER, "Your_Key_Name", 0, KEY_QUERY_VALUE, lngKey) Then
    End If

    lngLength = 256

    'Retrieve the value of the key
    lngRetval = RegQueryValueEx( _
        lngKey, "YourValueName", 0, 0, ByVal strValue, lngLength)
    MsgBox Left(strValue, lngLength)

    'Close the key
    RegCloseKey (lngKey)
End Sub

 








Related examples in the same category

1.Working with the Registry Using the VBA Registry Functions
2.Reads a value from the Windows Registry
3.Write a value from the Windows Registry
4.Using RegSetValueEx to Write Information to the Registry