RegistryKey::CreateSubKey Method (String^, Boolean)

.NET Framework (current version)
 

Creates a new subkey or opens an existing subkey with the specified access.

Available starting in .NET Framework 4.6

Namespace:   Microsoft.Win32
Assembly:  mscorlib (in mscorlib.dll)

public:
[ComVisibleAttribute(false)]
RegistryKey^ CreateSubKey(
	String^ subkey,
	bool writable
)

Parameters

subkey
Type: System::String^

The name or path of the subkey to create or open. This string is not case-sensitive.

writable
Type: System::Boolean

true to indicate the new subkey is writable; otherwise, false.

Return Value

Type: Microsoft.Win32::RegistryKey^

The newly created subkey, or null if the operation failed. If a zero-length string is specified for subkey, the current RegistryKey object is returned.

Exception Condition
ArgumentNullException

subkey is null.

SecurityException

The user does not have the permissions required to create or open the registry key.

UnauthorizedAccessException

The current RegistryKey cannot be written to; for example, it was not opened as a writable key, or the user does not have the necessary access rights.

IOException

The nesting level exceeds 510.

-or-

A system error occurred, such as deletion of the key, or an attempt to create a key in the LocalMachine root.

In order to perform this action, the user must have permission at this level and below in the registry hierarchy.

System_CAPS_cautionCaution

Do not expose RegistryKey objects in such a way that a malicious program could create thousands of meaningless subkeys or key/value pairs. For example, do not allow callers to enter arbitrary keys or values.

In order to use the CreateSubKey method, you must have an instance of the RegistryKey class. To get an instance of RegistryKey, use one of the static members of the Registry class.

.NET Framework
Available since 4.6
Return to top
Show: