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
);
| 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:
|
phkResult |
PHKEY |
A pointer to a variable that receives a handle to the opened registry key. |
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.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.