This documentation is archived and is not being maintained.

RegistryKey.OpenSubKey Method

Retrieves a specified subkey, with the write access as specified.

Overload List

Retrieves a subkey as read-only.

[Visual Basic] Overloads Public Function OpenSubKey(String) As RegistryKey
[C#] public RegistryKey OpenSubKey(string);
[C++] public: RegistryKey* OpenSubKey(String*);
[JScript] public function OpenSubKey(String) : RegistryKey;

Retrieves a specified subkey.

[Visual Basic] Overloads Public Function OpenSubKey(String, Boolean) As RegistryKey
[C#] public RegistryKey OpenSubKey(string, bool);
[C++] public: RegistryKey* OpenSubKey(String*, bool);
[JScript] public function OpenSubKey(String, Boolean) : RegistryKey;

Example

[Visual Basic, C#, C++] This code example is part of a larger example provided for the RegistryKey class.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of OpenSubKey. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
' Delete the non-secure password value.
testSettings = test9999.OpenSubKey("TestSettings", True)
testSettings.DeleteValue("password")

' Verify the deletion.
Console.WriteLine(CType(testSettings.GetValue( _
    "password", "Password not found."), String))
testSettings.Close()

[C#] 
using(RegistryKey 
    testSettings = test9999.OpenSubKey("TestSettings", true))
{
    // Delete the non-secure password value.
    testSettings.DeleteValue("password");

    // Verify the deletion.
    Console.WriteLine((string)testSettings.GetValue(
        "password", "Password not found."));
}

[C++] 
// Delete the non-secure password value.
testSettings = test9999->OpenSubKey(S"TestSettings", true);
testSettings->DeleteValue(S"password");

// Verify the deletion.
Console::WriteLine(dynamic_cast<String*>(
    testSettings->GetValue("password", S"Password not found.")));
testSettings->Close();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

RegistryKey Class | RegistryKey Members | Microsoft.Win32 Namespace

Show: