Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

RegistryKey.OpenSubKey Method (String, RegistryKeyPermissionCheck, RegistryRights)


Retrieves the specified subkey for read or read/write access, requesting the specified access rights.

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

public RegistryKey OpenSubKey(
	string name,
	RegistryKeyPermissionCheck permissionCheck,
	RegistryRights rights


Type: System.String

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

Type: Microsoft.Win32.RegistryKeyPermissionCheck

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

Type: System.Security.AccessControl.RegistryRights

A bitwise combination of enumeration values that specifies the desired security access.

Return Value

Type: Microsoft.Win32.RegistryKey

The subkey requested, or null if the operation failed.

Exception Condition

name is null


permissionCheck contains an invalid value.


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


rights includes invalid registry rights values.


The user does not have the requested permissions.

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.

The access specified for permissionCheck takes precedence over the access specified for rights. For example, if you specify RegistryKeyPermissionCheck.ReadSubTree for permissionCheck and RegistryRights.WriteKey for rights, an attempt to write to the subkey throws an exception.

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.


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


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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft