INtime SDK Help
RegCreateKeyEx (iwin32)
INtime SDK v7 > About INtime > Alternate APIs > iwin32 API > iwin32 API > RegCreateKeyEx (iwin32)

Creates the specified registry key. If the key already exists, the call opens it.

LONG RegCreateKeyEx(
    HKEY hKey,
    LPCTSTR lpSubKey,
    DWORD Reserved,
    LPTSTR lpClass,
    DWORD dwOptions,
    REGSAM samDesired,
    LPSECURITY_ATTRIBUTES lpSecurityAttributes,
    PHKEY phkResult,
    LPDWORD lpdwDisposition
);

Parameters

hKey
Handle to a currently open key or one of these predefined reserved handle values:

HKEY_CLASSES_ROOT HKEY_CURRENT_CONFIG HKEY_CURRENT_USER HKEY_LOCAL_MACHINE HKEY_USERS

The key opened or created by this call is a subkey of the key identified by the hKey parameter.

lpSubKey
Pointer to a null-terminated string that specifies the name of a subkey that this function opens or creates. The specified subkey 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
Reserved; must be zero.
lpClass
Pointer to a null-terminated string that specifies this key's class (object type). If the key already exists, this parameter is ignored.
dwOptions
Specifies one of these special options for the key:
REG_OPTION_NON_VOLATILE (Default) This key is not volatile. The information is stored in a file and is preserved when the system restarts.
REG_OPTION_VOLATILE This key is volatile; the information is stored in memory and not preserved when the system restarts. If the key already exists, this flag is ignored.
REG_OPTION_BACKUP_RESTORE If this flag is set, the call ignores the samDesired parameter and attempts to open the key with the access required to backup or restore the key.

If the RT Registry Server has the SE_BACKUP_NAME privilege enabled, the key opens with ACCESS_SYSTEM_SECURITY and KEY_READ access.

If the RT Registry Server has the SE_RESTORE_NAME privilege enabled, the key opens with ACCESS_SYSTEM_SECURITY and KEY_WRITE access.

If both privileges are enabled, the key has combined accesses for both privileges.

samDesired
Specifies an access mask that specifies one of these security access levels for the new key:
KEY_ALL_ACCESS Combination of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, KEY_CREATE_SUB_KEY, KEY_CREATE_LINK, and KEY_SET_VALUE access.
KEY_CREATE_LINK Permission to create a symbolic link.
KEY_CREATE_SUB_KEY Permission to create subkeys.
KEY_ENUMERATE_SUB_KEYS Permission to enumerate subkeys.
KEY_EXECUTE Permission for read access.
KEY_NOTIFY Permission for change notification.
KEY_QUERY_VALUE Permission to query subkey data.
KEY_READ Combination of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY access.
KEY_SET_VALUE Permission to set subkey data.
KEY_WRITE Combination of KEY_SET_VALUE and KEY_CREATE_SUB_KEY access.
lpSecurityAttributes
This parameter must be NULL. The key gets a default security descriptor.
phkResult
Pointer to a variable that receives a handle to the opened or created key. When you no longer need the returned handle, call RegCloseKey to close it.
lpdwDisposition
Pointer to a variable that receives one of these disposition values:
REG_CREATED_NEW_KEY The key did not exist and was created.
REG_OPENED_EXISTING_KEY The key existed and was simply opened without being changed.

Remarks

The key that this function creates has no value. To set key values, an application can use RegSetValueEx.

The key identified by the hKey parameter must be opened with KEY_CREATE_SUB_KEY access. To open the key, use either this function or RegOpenKeyEx.

An application cannot create a key under HKEY_USERS or HKEY_LOCAL_MACHINE.

An application can use this function to temporarily lock a portion of the registry. When the locking process creates a new key, it receives the disposition value REG_CREATED_NEW_KEY, indicating that it owns the lock. Another process trying to create the same key receives the disposition value REG_OPENED_EXISTING_KEY, indicating that another process already owns the lock.

Return Values

ERROR_SUCCESS
Success.
A nonzero status code defined in RTWIN32.H
Failure. For extended error information, see GetLastError

Requirements

Versions Defined in Include Link to
INtime 3.0 intime/rt/include/iwin32.h iwin32.h
iwin32rt.h
rt.lib

Note

This function operates in the real-time portion of your application.

See Also

RegCloseKey, RegOpenKeyEx, RegSaveKey, RegSetValueEx, iwin32 API, iwin32 Overview