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)

[ComVisibleAttribute(false)]
public RegistryKey OpenSubKey(
	string name,
	RegistryKeyPermissionCheck permissionCheck,
	RegistryRights rights
)

Parameters

name
Type: System.String

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

permissionCheck
Type: Microsoft.Win32.RegistryKeyPermissionCheck

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

rights
Type: System.Security.AccessControl.RegistryRights

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

Return Value

Type: Microsoft.Win32.RegistryKey
A RegistryKey object representing the subkey requested, or null if the operation failed.

ExceptionCondition
ArgumentNullException

name is null

ArgumentException

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

-or-

permissionCheck contains an invalid value.

ObjectDisposedException

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

SecurityException

rights includes invalid registry rights values.

-or-

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.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft