RegistryKey.OpenSubKey 方法

定义

检索指定的子项。Retrieves the specified subkey.

重载

OpenSubKey(String, Boolean)

检索指定的子项,并指定是否将写访问权限应用于该项。Retrieves a specified subkey, and specifies whether write access is to be applied to the key.

OpenSubKey(String, RegistryKeyPermissionCheck, RegistryRights)

检索指定的子项以进行读取或读/写访问,请求指定的访问权限。Retrieves the specified subkey for read or read/write access, requesting the specified access rights.

OpenSubKey(String, RegistryRights)

检索具有指定名称和访问权限的子项。Retrieves a subkey with the specified name and access rights. 从 .NET Framework 4.6 开始可用。Available starting with .NET Framework 4.6.

OpenSubKey(String)

以只读方式检索子项。Retrieves a subkey as read-only.

OpenSubKey(String, RegistryKeyPermissionCheck)

检索指定的子项以进行读取或读/写访问。Retrieves the specified subkey for read or read/write access.

OpenSubKey(String, Boolean)

检索指定的子项,并指定是否将写访问权限应用于该项。Retrieves a specified subkey, and specifies whether write access is to be applied to the key.

public:
 Microsoft::Win32::RegistryKey ^ OpenSubKey(System::String ^ name, bool writable);
public Microsoft.Win32.RegistryKey OpenSubKey (string name, bool writable);
member this.OpenSubKey : string * bool -> Microsoft.Win32.RegistryKey
Public Function OpenSubKey (name As String, writable As Boolean) As RegistryKey

参数

name
String

要打开的子项的名称或路径。Name or path of the subkey to open.

writable
Boolean

如果需要项的写访问权限,则设置为 trueSet to true if you need write access to the key.

返回

请求的子项;如果操作失败,则为 nullThe subkey requested, or null if the operation failed.

异常

namenullname is null.

RegistryKey 已关闭(无法访问已关闭的项)。The RegistryKey is closed (closed keys cannot be accessed).

用户没有在指定模式下访问注册表项所需的权限。The user does not have the permissions required to access the registry key in the specified mode.

示例

下面的代码示例创建一个测试键,并使用OpenSubKey方法将其打开,同时演示方法的两个重载。The following code example creates a test key and uses the OpenSubKey method to open it, demonstrating both overloads of the method.

#using <Microsoft.VisualBasic.dll>

using namespace System;
using namespace Microsoft::Win32;
using namespace Microsoft::VisualBasic;

int main()
{
    // Delete and recreate the test key.
    Registry::CurrentUser->DeleteSubKey( L"RegistryOpenSubKeyExample", false );
    RegistryKey ^ rk = Registry::CurrentUser->CreateSubKey( L"RegistryOpenSubKeyExample" );
    rk->Close();

    // Obtain an instance of RegistryKey for the CurrentUser registry
    // root.
    RegistryKey ^ rkCurrentUser = Registry::CurrentUser;

    // Obtain the test key (read-only) and display it.
    RegistryKey ^ rkTest = rkCurrentUser->OpenSubKey( L"RegistryOpenSubKeyExample" );
    Console::WriteLine( L"Test key: {0}", rkTest );
    rkTest->Close();
    rkCurrentUser->Close();

    // Obtain the test key in one step, using the CurrentUser registry
    // root.
    rkTest = Registry::CurrentUser->OpenSubKey( L"RegistryOpenSubKeyExample" );
    Console::WriteLine( L"Test key: {0}", rkTest );
    rkTest->Close();

    // Open the test key in read/write mode.
    rkTest = Registry::CurrentUser->OpenSubKey( L"RegistryOpenSubKeyExample", true );
    rkTest->SetValue( L"TestName", L"TestValue" );
    Console::WriteLine( L"Test value for TestName: {0}", rkTest->GetValue( L"TestName" ) );
    rkTest->Close();

    return 0;
} //Main
using System;
using Microsoft.Win32;
using Microsoft.VisualBasic;

public class Example
{
    public static void Main()
    {
        // Delete and recreate the test key.
        Registry.CurrentUser.DeleteSubKey("RegistryOpenSubKeyExample", false);
        RegistryKey rk = Registry.CurrentUser.CreateSubKey("RegistryOpenSubKeyExample");
        rk.Close();

        // Obtain an instance of RegistryKey for the CurrentUser registry 
        // root. 
        RegistryKey rkCurrentUser = Registry.CurrentUser;

        // Obtain the test key (read-only) and display it.
        RegistryKey rkTest = rkCurrentUser.OpenSubKey("RegistryOpenSubKeyExample");
        Console.WriteLine("Test key: {0}", rkTest);
        rkTest.Close();
        rkCurrentUser.Close();

        // Obtain the test key in one step, using the CurrentUser registry 
        // root.
        rkTest = Registry.CurrentUser.OpenSubKey("RegistryOpenSubKeyExample");
        Console.WriteLine("Test key: {0}", rkTest);
        rkTest.Close();

        // Open the test key in read/write mode.
        rkTest = Registry.CurrentUser.OpenSubKey("RegistryOpenSubKeyExample", true);
        rkTest.SetValue("TestName", "TestValue");
        Console.WriteLine("Test value for TestName: {0}", rkTest.GetValue("TestName"));
        rkTest.Close();
    } //Main
} //Example
Imports Microsoft.Win32

Public Class Example
    Public Shared Sub Main()
        ' Delete and recreate the test key.
        Registry.CurrentUser.DeleteSubKey("RegistryOpenSubKeyExample", False)
        Dim rk As RegistryKey = Registry.CurrentUser.CreateSubKey("RegistryOpenSubKeyExample")
        rk.Close

        ' Obtain an instance of RegistryKey for the CurrentUser registry 
        ' root. 
        Dim rkCurrentUser As RegistryKey = Registry.CurrentUser

        ' Obtain the test key (read-only) and display it.
        Dim rkTest As RegistryKey = rkCurrentUser.OpenSubKey("RegistryOpenSubKeyExample")
        Console.WriteLine("Test key: {0}", rkTest)
        rkTest.Close
        rkCurrentUser.Close

        ' Obtain the test key in one step, using the CurrentUser registry 
        ' root.
        rkTest = Registry.CurrentUser.OpenSubKey("RegistryOpenSubKeyExample")
        Console.WriteLine("Test key: {0}", rkTest)
        rkTest.Close

        ' Obtain the test key in read/write mode.
        rkTest = Registry.CurrentUser.OpenSubKey("RegistryOpenSubKeyExample", True)
        rkTest.SetValue("TestName", "TestValue")
        Console.WriteLine("Test value for TestName: {0}", rkTest.GetValue("TestName"))
        rkTest.Close
    End Sub
End Class

注解

如果请求的项不存在,则此方法返回null ,而不是引发异常。If the requested key does not exist, this method returns null instead of throwing an exception.

如果writabletrue,则将打开该密钥以进行读写,否则,将以只读方式打开该密钥。If writable is true, the key will be opened for reading and writing, otherwise, the key will be opened as read-only.

若要使用OpenSubKey方法,必须具有RegistryKey方法的实例。In order to use the OpenSubKey method, you must have an instance of the RegistryKey method. 若要获取的RegistryKey实例,请使用Registry类的静态成员之一。To get an instance of RegistryKey, use one of the static members of the Registry class.

安全性

RegistryPermission
用于读取指定的注册表项。for the ability to read the specified registry key. 关联的枚举:ReadAssociated enumeration: Read

SecurityPermission
用于访问指定注册表项(如果它是远程密钥)的功能。for the ability to access the specified registry key if it is a remote key. 关联的枚举:UnmanagedCodeAssociated enumeration: UnmanagedCode

另请参阅

OpenSubKey(String, RegistryKeyPermissionCheck, RegistryRights)

检索指定的子项以进行读取或读/写访问,请求指定的访问权限。Retrieves the specified subkey for read or read/write access, requesting the specified access rights.

public:
 Microsoft::Win32::RegistryKey ^ OpenSubKey(System::String ^ name, Microsoft::Win32::RegistryKeyPermissionCheck permissionCheck, System::Security::AccessControl::RegistryRights rights);
[System.Runtime.InteropServices.ComVisible(false)]
public Microsoft.Win32.RegistryKey OpenSubKey (string name, Microsoft.Win32.RegistryKeyPermissionCheck permissionCheck, System.Security.AccessControl.RegistryRights rights);
member this.OpenSubKey : string * Microsoft.Win32.RegistryKeyPermissionCheck * System.Security.AccessControl.RegistryRights -> Microsoft.Win32.RegistryKey
Public Function OpenSubKey (name As String, permissionCheck As RegistryKeyPermissionCheck, rights As RegistryRights) As RegistryKey

参数

name
String

要创建或打开的子项的名称或路径。The name or path of the subkey to create or open.

permissionCheck
RegistryKeyPermissionCheck

用于指定打开该项是进行读取还是读取/写入访问的枚举值之一。One of the enumeration values that specifies whether the key is opened for read or read/write access.

rights
RegistryRights

枚举值的按位组合,它指定所需的安全访问。A bitwise combination of enumeration values that specifies the desired security access.

返回

请求的子项;如果操作失败,则为 nullThe subkey requested, or null if the operation failed.

属性

异常

namenullname is null

permissionCheck 包含无效值。permissionCheck contains an invalid value.

RegistryKey 已关闭(无法访问已关闭的项)。The RegistryKey is closed (closed keys cannot be accessed).

rights 包含无效的注册表权限值。rights includes invalid registry rights values.

-or- 用户没有所要求的权限。The user does not have the requested permissions.

注解

如果请求的项不存在,则此null方法将返回,而不是引发异常。Rather than throwing an exception, this method returns null if the requested key does not exist.

如果permissionCheckRegistryKeyPermissionCheck.ReadSubTree permissionCheck RegistryKeyPermissionCheck.Default RegistryKeyPermissionCheck.ReadWriteSubTree,则打开密钥以进行读取和写入; 如果为或,则将打开密钥以供读取,除非已打开父键。 RegistryKeyPermissionCheck.ReadWriteSubTreeIf 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.

permissionCheck指定的访问权限优先于为rights指定的访问权限。The access specified for permissionCheck takes precedence over the access specified for rights. RegistryKeyPermissionCheck.ReadSubTree例如,如果为permissionCheck指定和RegistryRights.WriteKey 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.

若要使用OpenSubKey方法,必须具有RegistryKey类的实例。In order to use the OpenSubKey method, you must have an instance of the RegistryKey class. 若要获取的RegistryKey实例,请使用Registry类的静态成员之一。To get an instance of RegistryKey, use one of the static members of the Registry class.

安全性

RegistryPermission
用于读取指定的注册表项。for the ability to read the specified registry key. 关联的枚举:ReadAssociated enumeration: Read

SecurityPermission
用于访问指定注册表项(如果它是远程密钥)的功能。for the ability to access the specified registry key if it is a remote key. 关联的枚举:UnmanagedCodeAssociated enumeration: UnmanagedCode

另请参阅

OpenSubKey(String, RegistryRights)

检索具有指定名称和访问权限的子项。Retrieves a subkey with the specified name and access rights. 从 .NET Framework 4.6 开始可用。Available starting with .NET Framework 4.6.

public:
 Microsoft::Win32::RegistryKey ^ OpenSubKey(System::String ^ name, System::Security::AccessControl::RegistryRights rights);
[System.Runtime.InteropServices.ComVisible(false)]
public Microsoft.Win32.RegistryKey OpenSubKey (string name, System.Security.AccessControl.RegistryRights rights);
member this.OpenSubKey : string * System.Security.AccessControl.RegistryRights -> Microsoft.Win32.RegistryKey
Public Function OpenSubKey (name As String, rights As RegistryRights) As RegistryKey

参数

name
String

要创建或打开的子项的名称或路径。The name or path of the subkey to create or open.

rights
RegistryRights

注册表项的权限。The rights for the registry key.

返回

请求的子项;如果操作失败,则为 nullThe subkey requested, or null if the operation failed.

属性

异常

namenullname is null.

RegistryKey 已关闭(无法访问已关闭的项)。The RegistryKey is closed (closed keys cannot be accessed).

用户没有在指定模式下访问注册表项所需的权限。The user does not have the permissions required to access the registry key in the specified mode.

注解

必须先打开密钥,然后才能使用其他方法和属性进行操作。You must open a key before it can be manipulated with other methods and properties. 若要修改某个密钥,必须使用允许你指定写入访问权限OpenSubKey的方法重载打开它。To modify a key, you must open it with an overload of the OpenSubKey method that allows you to specify write access.

OpenSubKey(String)

以只读方式检索子项。Retrieves a subkey as read-only.

public:
 Microsoft::Win32::RegistryKey ^ OpenSubKey(System::String ^ name);
public Microsoft.Win32.RegistryKey OpenSubKey (string name);
member this.OpenSubKey : string -> Microsoft.Win32.RegistryKey
Public Function OpenSubKey (name As String) As RegistryKey

参数

name
String

要以只读方式打开的子项的名称或路径。The name or path of the subkey to open as read-only.

返回

请求的子项;如果操作失败,则为 nullThe subkey requested, or null if the operation failed.

异常

namenullname is null

RegistryKey 已关闭(无法访问已关闭的项)。The RegistryKey is closed (closed keys cannot be accessed).

用户没有读取注册表项所需的权限。The user does not have the permissions required to read the registry key.

示例

下面的代码示例创建一个测试键,并使用OpenSubKey方法将其打开,同时演示方法的两个重载。The following code example creates a test key and uses the OpenSubKey method to open it, demonstrating both overloads of the method.

#using <Microsoft.VisualBasic.dll>

using namespace System;
using namespace Microsoft::Win32;
using namespace Microsoft::VisualBasic;

int main()
{
    // Delete and recreate the test key.
    Registry::CurrentUser->DeleteSubKey( L"RegistryOpenSubKeyExample", false );
    RegistryKey ^ rk = Registry::CurrentUser->CreateSubKey( L"RegistryOpenSubKeyExample" );
    rk->Close();

    // Obtain an instance of RegistryKey for the CurrentUser registry
    // root.
    RegistryKey ^ rkCurrentUser = Registry::CurrentUser;

    // Obtain the test key (read-only) and display it.
    RegistryKey ^ rkTest = rkCurrentUser->OpenSubKey( L"RegistryOpenSubKeyExample" );
    Console::WriteLine( L"Test key: {0}", rkTest );
    rkTest->Close();
    rkCurrentUser->Close();

    // Obtain the test key in one step, using the CurrentUser registry
    // root.
    rkTest = Registry::CurrentUser->OpenSubKey( L"RegistryOpenSubKeyExample" );
    Console::WriteLine( L"Test key: {0}", rkTest );
    rkTest->Close();

    // Open the test key in read/write mode.
    rkTest = Registry::CurrentUser->OpenSubKey( L"RegistryOpenSubKeyExample", true );
    rkTest->SetValue( L"TestName", L"TestValue" );
    Console::WriteLine( L"Test value for TestName: {0}", rkTest->GetValue( L"TestName" ) );
    rkTest->Close();

    return 0;
} //Main
using System;
using Microsoft.Win32;
using Microsoft.VisualBasic;

public class Example
{
    public static void Main()
    {
        // Delete and recreate the test key.
        Registry.CurrentUser.DeleteSubKey("RegistryOpenSubKeyExample", false);
        RegistryKey rk = Registry.CurrentUser.CreateSubKey("RegistryOpenSubKeyExample");
        rk.Close();

        // Obtain an instance of RegistryKey for the CurrentUser registry 
        // root. 
        RegistryKey rkCurrentUser = Registry.CurrentUser;

        // Obtain the test key (read-only) and display it.
        RegistryKey rkTest = rkCurrentUser.OpenSubKey("RegistryOpenSubKeyExample");
        Console.WriteLine("Test key: {0}", rkTest);
        rkTest.Close();
        rkCurrentUser.Close();

        // Obtain the test key in one step, using the CurrentUser registry 
        // root.
        rkTest = Registry.CurrentUser.OpenSubKey("RegistryOpenSubKeyExample");
        Console.WriteLine("Test key: {0}", rkTest);
        rkTest.Close();

        // Open the test key in read/write mode.
        rkTest = Registry.CurrentUser.OpenSubKey("RegistryOpenSubKeyExample", true);
        rkTest.SetValue("TestName", "TestValue");
        Console.WriteLine("Test value for TestName: {0}", rkTest.GetValue("TestName"));
        rkTest.Close();
    } //Main
} //Example
Imports Microsoft.Win32

Public Class Example
    Public Shared Sub Main()
        ' Delete and recreate the test key.
        Registry.CurrentUser.DeleteSubKey("RegistryOpenSubKeyExample", False)
        Dim rk As RegistryKey = Registry.CurrentUser.CreateSubKey("RegistryOpenSubKeyExample")
        rk.Close

        ' Obtain an instance of RegistryKey for the CurrentUser registry 
        ' root. 
        Dim rkCurrentUser As RegistryKey = Registry.CurrentUser

        ' Obtain the test key (read-only) and display it.
        Dim rkTest As RegistryKey = rkCurrentUser.OpenSubKey("RegistryOpenSubKeyExample")
        Console.WriteLine("Test key: {0}", rkTest)
        rkTest.Close
        rkCurrentUser.Close

        ' Obtain the test key in one step, using the CurrentUser registry 
        ' root.
        rkTest = Registry.CurrentUser.OpenSubKey("RegistryOpenSubKeyExample")
        Console.WriteLine("Test key: {0}", rkTest)
        rkTest.Close

        ' Obtain the test key in read/write mode.
        rkTest = Registry.CurrentUser.OpenSubKey("RegistryOpenSubKeyExample", True)
        rkTest.SetValue("TestName", "TestValue")
        Console.WriteLine("Test value for TestName: {0}", rkTest.GetValue("TestName"))
        rkTest.Close
    End Sub
End Class

注解

必须先打开密钥,然后才能使用其他方法和属性进行操作。You must open a key before it can be manipulated with other methods and properties. 若要修改某个密钥,必须使用OpenSubKey方法的重载打开该密钥,该方法允许你指定写入访问权限,如OpenSubKey(String, RegistryKeyPermissionCheck)重载或OpenSubKey(String, Boolean)重载。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.

如果找不到指定的子项, null则返回。If the specified subkey cannot be found, then null is returned.

若要使用OpenSubKey方法,必须具有的RegistryKey实例。In order to use the OpenSubKey method, you must have an instance of RegistryKey. 若要获取的RegistryKey实例,请使用Registry类的静态成员之一。To get an instance of RegistryKey, use the one of the static members of the Registry class.

安全性

RegistryPermission
用于读取指定的注册表项。for the ability to read the specified registry key. 关联的枚举:ReadAssociated enumeration: Read

SecurityPermission
用于访问指定注册表项(如果它是远程密钥)的功能。for the ability to access the specified registry key if it is a remote key. 关联的枚举:UnmanagedCodeAssociated enumeration: UnmanagedCode

另请参阅

OpenSubKey(String, RegistryKeyPermissionCheck)

检索指定的子项以进行读取或读/写访问。Retrieves the specified subkey for read or read/write access.

public:
 Microsoft::Win32::RegistryKey ^ OpenSubKey(System::String ^ name, Microsoft::Win32::RegistryKeyPermissionCheck permissionCheck);
[System.Runtime.InteropServices.ComVisible(false)]
public Microsoft.Win32.RegistryKey OpenSubKey (string name, Microsoft.Win32.RegistryKeyPermissionCheck permissionCheck);
member this.OpenSubKey : string * Microsoft.Win32.RegistryKeyPermissionCheck -> Microsoft.Win32.RegistryKey
Public Function OpenSubKey (name As String, permissionCheck As RegistryKeyPermissionCheck) As RegistryKey

参数

name
String

要创建或打开的子项的名称或路径。The name or path of the subkey to create or open.

permissionCheck
RegistryKeyPermissionCheck

用于指定打开该项是进行读取还是读取/写入访问的枚举值之一。One of the enumeration values that specifies whether the key is opened for read or read/write access.

返回

请求的子项;如果操作失败,则为 nullThe subkey requested, or null if the operation failed.

属性

异常

namenullname is null

permissionCheck 包含无效值。permissionCheck contains an invalid value.

RegistryKey 已关闭(无法访问已关闭的项)。The RegistryKey is closed (closed keys cannot be accessed).

用户没有读取注册表项所需的权限。The user does not have the permissions required to read the registry key.

示例

下面的代码示例创建一个包含100键/值对的子项并将其关闭。The following code example creates a subkey containing 100 key/value pairs and closes it. 该示例使用Default打开子项,记录读取所有值所用的时间,并关闭子项。The example opens the subkey with Default, records the time it takes to read all the values, and closes the subkey. 该示例使用ReadSubTree打开该子项,并记录读取所有值所用的时间。The example opens the subkey with ReadSubTree and records the time it takes to read all the values. 最后,该示例计算并显示改进百分比。Finally, the example computes and displays the percentage improvement.

using System;
using Microsoft.Win32;
using System.Diagnostics;

public class Example
{
    public static void Main()
    {
        const int LIMIT = 100;
        RegistryKey cu = Registry.CurrentUser;
        const string testKey = "RegistryKeyPermissionCheckExample";

        Console.WriteLine("Generating {0} key/value pairs.", LIMIT);
        RegistryKey rk = cu.CreateSubKey(testKey);
        for (int i = 0; i < LIMIT; i++)
        {
            rk.SetValue("Key" + i, i);
        }

        rk.Close();

        Stopwatch s = new Stopwatch();

        // On the default setting, security is checked every time
        // a key/value pair is read.
        rk = cu.OpenSubKey(testKey, RegistryKeyPermissionCheck.Default);
        
        s.Start();
        for (int i = 0; i < LIMIT; i++)
        {
            rk.GetValue("Key" + i, i);
        }
        s.Stop();
        rk.Close();
        long delta1 = s.ElapsedTicks;

        s.Reset();

        // When the key is opened with ReadSubTree, security is 
        // not checked when the values are read.
        rk = cu.OpenSubKey(testKey, RegistryKeyPermissionCheck.ReadSubTree);
        
        s.Start();
        for (int i = 0; i < LIMIT; i++)
        {
            rk.GetValue("Key" + i, i);
        }
        s.Stop();
        rk.Close();
        long delta2 = s.ElapsedTicks;

        double faster = (double) (delta1 - delta2) / (double) delta1;
        Console.WriteLine("ReadSubTree is {0}% faster for {1} values.",
            (faster * 100).ToString("0.0"), LIMIT);

        cu.DeleteSubKey(testKey);
    }
}

/* This code example produces output similar to the following:

Generating 100 key/value pairs.
ReadSubTree is 23.4% faster for 100 values.
 */
Imports Microsoft.Win32
Imports System.Diagnostics

Public Class Example
    
    Public Shared Sub Main() 

        Const LIMIT As Integer = 100
        Dim cu As RegistryKey = Registry.CurrentUser
        Const testKey As String = "RegistryKeyPermissionCheckExample"
        
        Console.WriteLine("Generating {0} key/value pairs.", LIMIT)
        Dim rk As RegistryKey = cu.CreateSubKey(testKey)

        For i As Integer = 0 To LIMIT
            rk.SetValue("Key" & i, i)
        Next i
        
        rk.Close()
        
        Dim s As New Stopwatch()
        
        ' On the default setting, security is checked every time
        ' a key/value pair is read.
        rk = cu.OpenSubKey(testKey, _
            RegistryKeyPermissionCheck.Default)
        
        s.Start()
        For i As Integer = 0 To LIMIT
            rk.GetValue("Key" & i, i)
        Next i
        s.Stop()
        rk.Close()
        Dim delta1 As Long = s.ElapsedTicks
        
        s.Reset()
        
        ' When the key is opened with ReadSubTree, security is 
        ' not checked when the values are read.
        rk = cu.OpenSubKey(testKey, _
            RegistryKeyPermissionCheck.ReadSubTree)
        
        s.Start()
        For i As Integer = 0 To LIMIT
            rk.GetValue("Key" & i, i)
        Next i
        s.Stop()
        rk.Close()
        Dim delta2 As Long = s.ElapsedTicks
        
        Dim faster As Double = _
            CDbl(delta1 - delta2) * 100.0 / CDbl(delta1)
        Console.WriteLine("ReadSubTree is {0}% faster for {1} values.", _
            faster.ToString("0.0"), LIMIT)
        
        cu.DeleteSubKey(testKey)
    
    End Sub 
End Class 

' This code example produces output similar to the following:
'
'Generating 100 key/value pairs.
'ReadSubTree is 23.4% faster for 100 values.
' 

注解

如果请求的项不存在,则此null方法将返回,而不是引发异常。Rather than throwing an exception, this method returns null if the requested key does not exist.

如果permissionCheckRegistryKeyPermissionCheck.ReadSubTree permissionCheck RegistryKeyPermissionCheck.Default RegistryKeyPermissionCheck.ReadWriteSubTree,则打开密钥以进行读取和写入; 如果为或,则将打开密钥以供读取,除非已打开父键。 RegistryKeyPermissionCheck.ReadWriteSubTreeIf 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.

若要使用OpenSubKey方法,必须具有RegistryKey类的实例。In order to use the OpenSubKey method, you must have an instance of the RegistryKey class. 若要获取的RegistryKey实例,请使用Registry类的静态成员之一。To get an instance of RegistryKey, use one of the static members of the Registry class.

安全性

RegistryPermission
用于读取指定的注册表项。for the ability to read the specified registry key. 关联的枚举:ReadAssociated enumeration: Read

SecurityPermission
用于访问指定注册表项(如果它是远程密钥)的功能。for the ability to access the specified registry key if it is a remote key. 关联的枚举:UnmanagedCodeAssociated enumeration: UnmanagedCode

另请参阅

适用于