RegOpenKeyEx

RegOpenKeyEx opens the specified registry key.

Syntax

LONG RegOpenKeyEx(
    HKEY       hKey,
    LPCTSTR    lpSubKey,
    DWORD      ulOptions, 
    REGSAM     samDesired, 
    PHKEY      phkResult 
  );

Parameters

hKey

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_LOCAL_MACHINE

HKEY_USERS

lpSubKey

The name of a key that this function opens or creates. This key must be a subkey of the key identified by the hKey parameter. Key names are not case sensitive. If this parameter is NULL or a pointer to an empty string, the function returns the handle to the predefined hKey parameter.

ulOptions

This parameter is reserved and must be zero.

samDesired

A mask that specifies the desired access rights to the key. The function fails if the security descriptor of the key does not permit the requested access for the calling process.

Value

Meaning

KEY_QUERY_VALUE

Read key values.

KEY_SET_VALUE

Write key values.

KEY_CREATE_SUB_KEY

Create subkeys for the key.

KEY_ENUMERATE_SUB_KEYS

Read the key's subkeys.

KEY_CREATE_LINK

Create a symbolic link to the key. This flag is not used by device and intermediate drivers.

KEY_READ

Combines the STANDARD_RIGHTS_READ, KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY values.

KEY_WRITE

Combines the STANDARD_RIGHTS_WRITE, KEY_SET_VALUE, and KEY_CREATE_SUB_KEY access rights.

KEY_EXECUTE

Equivalent to KEY_READ.

KEY_ALL_ACCESS

Combines the STANDARD_RIGHTS_REQUIRED, KEY_QUERY_VALUE, KEY_SET_VALUE, KEY_CREATE_SUB_KEY, KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, and KEY_CREATE_LINK access rights.

phkResult

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.

Remarks

Unlike the RegCreateKeyEx function, the RegOpenKeyEx function does not create the specified key if the key does not exist in the registry. An application should call RegCloseKey when the handle is no longer in use, or upon application exit.

Requirements

Minimum Supported Version RTX64 2013
Header windows.h
Library Rtx_Rtss.lib

See Also

Registry API

RegCloseKey

RegCreateKeyEx

RegDeleteKey

RegOpenKey