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
RegOpenKeyEx opens a key in the Windows registry. The handle it returns must be used when you read to or write from any values under that key. This function will not create the key if it does not exist. The function puts a handle to the opened key into the variable passed as phkResult. The function returns 0 if successful, or a non-zero value error code if an error occured.
Example:
' Read the Data value under the key:
' HKEY_CURRENT_USER\Software\Dummy\DummyApp\1.0\
subkey = "Software\Dummy\DummyApp\1.0" ' key name
x = RegOpenKeyEx(HKEY_CURRENT_USER, subkey, 0, KEY_READ, hregkey)
If x <> 0 Then ' error opening key -- abort!
Debug.Print "Could not open registry key."
Exit Sub
End If
'(put rest of code here)
x = RegCloseKey(hregkey)
Related Calls: RegCloseKey, RegCreateKeyEx
Category: Registry
Back to the index.