This documentation is archived and is not being maintained.

RegistryKey.OpenSubKey Method (String, RegistryKeyPermissionCheck, RegistryRights)

Note: This method is new in the .NET Framework version 2.0.

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
/** @attribute ComVisibleAttribute(false) */ 
public RegistryKey OpenSubKey (
	String name, 
	RegistryKeyPermissionCheck permissionCheck, 
	RegistryRights rights
public function OpenSubKey (
	name : String, 
	permissionCheck : RegistryKeyPermissionCheck, 
	rights : RegistryRights
) : RegistryKey



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


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


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

Return Value

A RegistryKey object representing the subkey requested, or a null reference (Nothing in Visual Basic) if the operation failed.

Exception typeCondition


name is a null reference (Nothing in Visual Basic)


name is longer than the maximum length allowed (255 characters).


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 a null reference (Nothing in Visual Basic) 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.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0