NTSTATUS
ZwCreateKey(
OUT PHANDLE KeyHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes,
IN ULONG TitleIndex,
IN PUNICODE_STRING Class, /* optional*/
IN ULONG CreateOptions,
OUT PULONG Disposition /* optional*/
);
ZwCreateKey opens an existing key or creates a new key in the registry.
DesiredAccess Flags |
Meaning |
KEY_QUERY_VALUE |
Value entries for the key can be read. |
KEY_SET_VALUE |
Value entries for the key can be written. |
KEY_CREATE_SUB_KEYS |
Subkeys for the key can be created. |
KEY_ENUMERATE_SUB_KEYS |
All subkeys for the key can be read. |
KEY_NOTIFY |
This flag is irrelevant to device and intermediate drivers, and to other kernel-mode code. |
KEY_CREATE_LINK |
A symbolic link to the key can be created. This flag is irrelvant to device and intermediate drivers. |
Callers of ZwCreateKey can specify one or a compatible combination of the following for any key object:
DesiredAccess to Key Values |
Maps to DesiredAccess Flags |
KEY_READ |
STANDARD_RIGHTS_READ, KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY |
KEY_WRITE |
STANDARD_RIGHTS_WRITE, KEY_SET_VALUE, and KEY_CREATE_SUBKEY |
KEY_EXECUTE |
KEY_READ. This value is irrelevant to device and intermediate drivers. |
KEY_ALL_ACCESS |
STANDARD_RIGHTS_ALL, KEY_QUERY_VALUE, KEY_SET_VALUE, KEY_CREATE_SUB_KEY, KEY_ENUMERATE_SUBKEY, KEY_NOTIFY and KEY_CREATE_LINK |
The STANDARD_RIGHTS_XXX are predefined system values used to enforce
security on system objects.
Value |
Meaning |
REG_OPTION_VOLATILE |
Key is not to be stored across boots. |
REG_OPTION_NON_VOLATILE |
Key is preserved when the system is rebooted. |
REG_OPTION_CREATE_LINK |
The created key is a symbolic link. This value is irrelevant to device and intermediate drivers. |
REG_OPTION_BACKUP_RESTORE |
Key is being opened or created with special privileges allowing backup/restore operations. This value is irrelevant to device and intermediate drivers. |
Value |
Meaning |
REG_CREATED_NEW_KEY |
A new key object was created. |
REG_OPENED_EXISTING_KEY |
An existing key object was opened. |
ZwCreateKey returns STATUS_SUCCESS if the given key was created or opened.
If the key specified by ObjectAttributes does not exist, an attempt is made to create it. For this attempt to succeed, the new key must be a direct subkey of the key referred to by KeyHandle, and the given KeyHandle must have been opened for KEY_CREATE_SUB_KEY access.
If the specified key already exists, it is opened and its value is not affected in any way.
The security attributes specified by ObjectAttributes when a key is created determine whether the specified DesiredAccess is granted on subsequent calls to ZwCreateKey and ZwOpenKey.
Callers of ZwCreateKey must be running at IRQL PASSIVE_LEVEL.
InitializeObjectAttributes, ZwClose, ZwDeleteKey, ZwEnumerateKey, ZwEnumerateValueKey, ZwFlushKey, ZwOpenKey, ZwQueryValueKey, ZwSetValueKey