RegOpenKeyEx

RegOpenKeyEx opens the specified registry key.

Syntax

Copy
LONG RegOpenKeyEx(
    [in]             HKEY       hKey,
    [in, optional]   LPCTSTR    lpSubKey,
    [in]             DWORD      ulOptions, 
    [in]             REGSAM     samDesired, 
    [out]            PHKEY      phkResult 
  );

Parameters

[in] 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:

[in, optional] 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.

[in] ulOptions

This parameter is reserved and must be zero.

[in] 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. Device and intermediate drivers do not use this flag.

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.

[out] 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 using the handle.

Return Value

If the function succeeds, it returns ERROR_SUCCESS. If the function fails, it returns a non-zero error code.

Remarks

Unlike the RegCreateKeyEx function, the RegOpenKeyEx function does not create the specified key if it 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 Header Library

wRTOS 1.0 SDK

windows.h

wRTOS_rtss.lib

See Also