The RegOpenKeyEx function opens the specified key.
LONG RegOpenKeyEx(
HKEY hKey, // handle to open key
LPCTSTR lpSubKey, // address of name of subkey to open
DWORD ulOptions, // reserved
REGSAM samDesired, // security access mask
PHKEY phkResult // address of handle to open key
);
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
Windows NT: HKEY_PERFORMANCE_DATA
Windows 95 and Windows 98: HKEY_DYN_DATA
Value | Meaning |
---|---|
KEY_ALL_ACCESS | Combination of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, KEY_CREATE_SUB_KEY, KEY_CREATE_LINK, and KEY_SET_VALUE access. |
KEY_CREATE_LINK | Permission to create a symbolic link. |
KEY_CREATE_SUB_KEY | Permission to create subkeys. |
KEY_ENUMERATE_SUB_KEYS | Permission to enumerate subkeys. |
KEY_EXECUTE | Permission for read access. |
KEY_NOTIFY | Permission for change notification. |
KEY_QUERY_VALUE | Permission to query subkey data. |
KEY_READ | Combination of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY access. |
KEY_SET_VALUE | Permission to set subkey data. |
KEY_WRITE | Combination of KEY_SET_VALUE and KEY_CREATE_SUB_KEY access. |
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.
Unlike the RegCreateKeyEx function, the RegOpenKeyEx function does not create the specified key if the key does not exist in the registry.
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winreg.h.
Import Library: Use advapi32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.
Registry Overview, Registry Functions, RegCloseKey, RegCreateKeyEx, RegDeleteKey, RegOpenKey