OpenKey method

The OpenKey method opens already existing key (passed to this method as parameter) in the Registry.  

BOOL OpenKey(
 BSTR Key,// The Registry key to open
 LONG Options,// Additional options
 LONG samDesired// The access mask
);


Parameters
  Key     [in] Determines the full name of the key. For instance: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\SW   Options     [in] This parameter defines additional options and can be one of the following values:    

ValueMeaning
REG_OPTION_NON_VOLATILE (0)This key is not volatile; this is the default. The information is stored in a file and is preserved when the system is restarted. The RegSaveKey function saves keys that are not volatile.
REG_OPTION_VOLATILE (1)

All keys created by the function are volatile. The information is stored in memory and is not preserved when the corresponding registry hive is unloaded. For HKEY_LOCAL_MACHINE, this occurs when the system is shut down. For registry keys loaded by the RegLoadKey function, this occurs when the corresponding RegUnLoadKey is performed. The RegSaveKey function does not save volatile keys. This flag is ignored for keys that already exist.

Windows Me/98/95:   This value is ignored. If it is specified, the RegCreateKeyEx function creates nonvolatile keys and returns ERROR_SUCCESS

REG_OPTION_BACKUP_RESTORE (4)

If this flag is set, the function ignores the samDesired parameter and attempts to open the key with the access required to backup or restore the key. If the calling thread has the SE_BACKUP_NAME privilege enabled, the key is opened with the ACCESS_SYSTEM_SECURITY and KEY_READ access rights. If the calling thread has the SE_RESTORE_NAME privilege enabled, the key is opened with the ACCESS_SYSTEM_SECURITY and KEY_WRITE access rights. If both privileges are enabled, the key has the combined access rights for both privileges. For more information, see Running with Special Privileges.

Windows Me/98/95:   This value is not supported

Note: the default value is 0 (REG_OPTION_NON_VOLATILE).

  samDesired     [in] This is the access mask that specifies the access rights for the key. It may have one of the following values:    

ValueMeaning
KEY_ALL_ACCESS (0x000f003f) 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.
KEY_CREATE_SUB_KEY (0x0004)Required to create a subkey of a registry key
KEY_ENUMERATE_SUB_KEYS (0x0008)Required to enumerate the subkeys of a registry key
KEY_EXECUTE (0x00020019)Equivalent to KEY_READ
KEY_NOTIFY (0x0010)Required to request change notifications for a registry key or for subkeys of a registry key
KEY_QUERY_VALUE (0x0001)Required to query the values of a registry key
KEY_READ (0x00020019)Combines the STANDARD_RIGHTS_READ, KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY values
KEY_SET_VALUE (0x0002)Required to create, delete, or set a registry value
KEY_WOW64_64KEY (0x0100)Enables a 64- or 32-bit application to open a 64-bit key on 64-bit Windows. This flag must be combined using the OR operator with the other flags in this table that either query or access registry values
KEY_WOW64_32KEY (0x0200)Enables a 64- or 32-bit application to open a 32-bit key on 64-bit Windows. This flag must be combined using the OR operator with the other flags in this table that either query or access registry values
KEY_WRITE (0x00020006)Combines the STANDARD_RIGHTS_WRITE, KEY_SET_VALUE, and KEY_CREATE_SUB_KEY access rights

Note: the default value is 0x000f003f (KEY_ALL_ACCESS).


Return values
  The CreateKey method returns TRUE if the specified key is successfully opened and FALSE otherwise.


See also
CreateKey, CloseKey method