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
Platforms: Win 32s, Win 95/98, Win NT
RegOpenKeyEx opens a key in the Windows registry. The handle it gives must be used when you read to or write from any values under that key. Unlike RegCreateKeyEx, 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:
' Open a key called HKEY_CURRENT_USER\Software\MyCorp\MyProgram\Config.
' Then create a "username" value under that key and set its value to "Rimmer".
Dim hregkey As Long ' receives handle to the opened registry key
Dim subkey As String ' name of the subkey to create
Dim retval As Long ' return value
' Set the name of the new key and the default security settings
subkey = "Software\MyCorp\MyProgram\Config"
' Open the registry key
retval = RegOpenKeyEx(HKEY_CURRENT_USER, subkey, 0, KEY_WRITE, hregkey)
If retval <> 0 Then ' error during open
Debug.Print "Error opening registry key -- aborting."
End ' terminate the program
End If
' Insert rest of code here.....
' Close the registry key
retval = RegCloseKey(hregkey)
See Also: RegCloseKey, RegCreateKeyEx
Category: Registry
Go back to the alphabetical Function listing.
Go back to the Reference section index.
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/r/regopenkeyex.html