RegistryKey::OpenSubKey Method (String^, RegistryKeyPermissionCheck)

 

Retrieves the specified subkey for read or read/write access.

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

public:
[ComVisibleAttribute(false)]
RegistryKey^ OpenSubKey(
	String^ name,
	RegistryKeyPermissionCheck permissionCheck
)

Parameters

name
Type: System::String^

The name or path of the subkey to create or open.

permissionCheck
Type: Microsoft.Win32::RegistryKeyPermissionCheck

One of the enumeration values that specifies whether the key is opened for read or read/write access.

Return Value

Type: Microsoft.Win32::RegistryKey^

The subkey requested, or null if the operation failed.

Exception Condition
ArgumentNullException

name is null

ArgumentException

permissionCheck contains an invalid value.

ObjectDisposedException

The RegistryKey is closed (closed keys cannot be accessed).

SecurityException

The user does not have the permissions required to read the registry key.

Rather than throwing an exception, this method returns null if the requested key does not exist.

If permissionCheck is RegistryKeyPermissionCheck::ReadWriteSubTree, the key is opened for reading and writing; if permissionCheck is RegistryKeyPermissionCheck::ReadSubTree or RegistryKeyPermissionCheck::Default, the key is opened for reading unless the parent key was opened with RegistryKeyPermissionCheck::ReadWriteSubTree.

In order to use the OpenSubKey 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.

The following code example creates a subkey containing 100 key/value pairs and closes it. The example opens the subkey with Default, records the time it takes to read all the values, and closes the subkey. The example opens the subkey with ReadSubTree and records the time it takes to read all the values. Finally, the example computes and displays the percentage improvement.

No code example is currently available or this language may not be supported.

RegistryPermission

for the ability to read the specified registry key. Associated enumeration: RegistryPermissionAccess::Read

SecurityPermission

for the ability to access the specified registry key if it is a remote key. Associated enumeration: SecurityPermissionFlag::UnmanagedCode

.NET Framework
Available since 2.0
Return to top
Show: