This documentation is archived and is not being maintained.

RegistryKey.OpenSubKey Method (String)

Retrieves a subkey as read-only.

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

member OpenSubKey : 
        name:string -> RegistryKey 

Parameters

name
Type: System.String
The name or path of the subkey to open as read-only.

Return Value

Type: Microsoft.Win32.RegistryKey
The subkey requested, or a null reference (Nothing in Visual Basic) if the operation failed.

ExceptionCondition
ArgumentNullException

name is a null reference (Nothing in Visual Basic)

ObjectDisposedException

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

SecurityException

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

You must open a key before it can be manipulated with other methods and properties. To modify a key, you must open it with an overload of the OpenSubKey method that allows you to specify write access, such as the OpenSubKey(String, RegistryKeyPermissionCheck) overload or the OpenSubKey(String, Boolean) overload.

If the specified subkey cannot be found, then a null reference (Nothing in Visual Basic) is returned.

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

The following code example creates a test key and uses the OpenSubKey method to open it, demonstrating both overloads of the method.

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

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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