RegOpenKeyEx

Opens an existing registry key. If the key does not exist, the function does not create it.

LSTATUS RegOpenKeyEx( HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult );

Parameters

Parameter Type Description
hKey HKEY A handle to an open registry key. The key must have been opened with write access.
lpSubKey LPCSTR The name of the registry subkey to open. For a full path, use backslashes to separate subkeys.
ulOptions DWORD This parameter is reserved and must be zero.
samDesired REGSAM A mask that specifies the desired access rights to the key. This parameter can be one or more of the following values:
  • KEY_ALL_ACCESS
  • KEY_CREATE_LINK
  • KEY_CREATE_SUB_KEY
  • KEY_ENUMERATE_SUB_KEYS
  • KEY_EXECUTE
  • KEY_NOTIFY
  • KEY_QUERY_VALUE
  • KEY_SET_INFORMATION
  • KEY_SET_VALUE
  • KEY_WOW64_64KEY
  • KEY_WOW64_32KEY
phkResult PHKEY A pointer to a variable that receives a handle to the opened registry key.

Return Value

If the function succeeds, the return value is a success code. If the function fails, the return value is a system error code that can be converted using FormatMessage.

  • ERROR_SUCCESS (0): The operation completed successfully.
  • ERROR_FILE_NOT_FOUND (2): The specified key or subkey does not exist.
  • ERROR_ACCESS_DENIED (5): The user does not have the required access rights to the key.

Remarks

To open a key under HKEY_LOCAL_MACHINE or HKEY_USERS, the calling process must have appropriate privileges.

The lpSubKey parameter can specify a path of subkeys. For example, "Software\MyCompany".

The samDesired parameter specifies the type of access you want to the key. If you only need to read values, use KEY_READ. If you need to write values, use KEY_WRITE. KEY_ALL_ACCESS grants all possible access rights.

The handle returned in phkResult must be closed by calling RegCloseKey when it is no longer needed.

See Also