The RegCreateKeyEx function creates the specified key. If the key already exists in the registry, the function opens it.
Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
Operating Systems Supported
Requires Windows NT 3.1 or later; Requires Windows 95 or later
Identifies a currently open key or any of the following predefined reserved handle values:
The key opened or created by the RegCreateKeyEx function is a subkey of the key identified by the hKey parameter.
Points to a null-terminated string specifying the name of a subkey that this function opens or creates. The subkey specified must be a subkey of the key identified by the hKey parameter. This subkey must not begin with the backslash character (‘\’). This parameter cannot be NULL.
Reserved; must be zero.
Points to a null-terminated string that specifies the class (object type) of this key. This parameter is ignored if the key already exists.
Specifies special options for the key. This parameter can be one of the following values.
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.
Windows NT: This key is volatile; the information is stored in memory and is not preserved when the system is restarted. The RegSaveKey function does not save volatile keys. This flag is ignored if the key already exists.
Windows 95: This value is ignored in Windows 95. If REG_OPTION_VOLATILE is specified, the RegCreateKeyEx function creates a nonvolatile key and returns ERROR_SUCCESS.
Windows NT: 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 ACCESS_SYSTEM_SECURITY and KEY_READ access. If the calling thread has the SE_RESTORE_NAME privilege enabled, the key is opened with ACCESS_SYSTEM_SECURITY and KEY_WRITE access. If both privileges are enabled, the key has the combined accesses for both privileges.
Windows 95: This flag is ignored. Windows 95 does not support security in its registry.
Specifies an access mask that specifies the desired security access for the new key. This parameter can be a combination of the following values:
Combination of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, KEY_CREATE_SUB_KEY, KEY_CREATE_LINK, and KEY_SET_VALUE access.
Permission to create a symbolic link.
Permission to create subkeys.
Permission to enumerate subkeys.
Permission for read access.
Permission for change notification.
Permission to query subkey data.
Combination of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY access.
Permission to set subkey data.
Combination of KEY_SET_VALUE and KEY_CREATE_SUB_KEY access.
Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpSecurityAttributes is NULL, the handle cannot be inherited.
Windows NT: The lpSecurityDescriptor member of the structure specifies a security descriptor for the new key. If lpSecurityAttributes is NULL, the key gets a default security descriptor.
Windows 95: The lpSecurityDescriptor member of the structure is ignored.
Points to a variable that receives the handle of the opened or created key.
Points to a variable that receives one of the following disposition values:
The key did not exist and was created.
The key existed and was simply opened without being changed.
If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value is a nonzero error code defined in WINERROR.H. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.