The CreateKey method creates the key (passed to this method as parameter) in the Registry.
|BSTR Key,||// The Registry key to create|
|LONG Options,||// Additional options|
|LONG samDesired||// The access mask|
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:
|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.|
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
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:
|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).
The CreateKey method returns TRUE if the specified key is successfully created and FALSE otherwise.