RegOpenKeyEx
Jump to navigation
Jump to search
Description
Opens the specified registry key. Note that key names are not case sensitive.
To perform transacted registry operations on a key, call the RegOpenKeyTransacted function.
Syntax
LONG WINAPI RegOpenKeyEx(
_In_ HKEY hKey,
_In_opt_ LPCTSTR lpSubKey,
_In_ DWORD ulOptions,
_In_ REGSAM samDesired,
_Out_ PHKEY phkResult
);
- hKey [in]
- A handle to an open registry key. This handle is returned by the RegCreateKeyEx or RegOpenKeyEx function, or it can be one of the following predefined keys:
- HKEY_CLASSES_ROOT
- HKEY_CURRENT_CONFIG
- HKEY_CURRENT_USER
- HKEY_LOCAL_MACHINE
- HKEY_USERS
- lpSubKey [in, optional]
- The name of the registry subkey to be opened.
- Key names are not case sensitive.
- The lpSubKey parameter can be a pointer to an empty string. If lpSubKey is a pointer to an empty string and hKey is HKEY_CLASSES_ROOT, phkResult receives the same hKey handle passed into the function. Otherwise, phkResult receives a new handle to the key specified by hKey.
- The lpSubKey parameter can be NULL only if hKey is one of the predefined keys. If lpSubKey is NULL and hKey is HKEY_CLASSES_ROOT, phkResult receives a new handle to the key specified by hKey. Otherwise, phkResult receives the same hKey handle passed in to the function.
- ulOptions [in]
- Specifies the option to apply when opening the key. Set this parameter to zero or the following:
Value Meaning REG_OPTION_OPEN_LINK The key is a symbolic link. Registry symbolic links should only be used when absolutely necessary.
- samDesired [in]
- A mask that specifies the desired access rights to the key to be opened. The function fails if the security descriptor of the key does not permit the requested access for the calling process. For more information, see Registry Key Security and Access Rights.
- phkResult [out]
- A pointer to a variable that receives a handle to the opened key. If the key is not one of the predefined registry keys, call the RegCloseKey function after you have finished using the handle.
Return value
If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.
Example
CODE:0040112C push offset hKey ; phkResult
CODE:00401131 push 3C000007h ; samDesired
CODE:00401136 push 0 ; ulOptions
CODE:00401138 push offset SubKey ; "SOFTWARE\\Netscape\\Netscape Navigator\"...
CODE:0040113D push 80000002h ; hKey
CODE:00401142 call RegOpenKeyExA
CODE:00401147 cmp eax, 0
CODE:0040114A jnz bad_boy