RegistryKeyPermissionCheck RegistryKeyPermissionCheck RegistryKeyPermissionCheck RegistryKeyPermissionCheck Enum

定义

指定在打开注册表项并访问它们的名称/值对时是否执行安全检查。Specifies whether security checks are performed when opening registry keys and accessing their name/value pairs.

public enum class RegistryKeyPermissionCheck
public enum RegistryKeyPermissionCheck
type RegistryKeyPermissionCheck = 
Public Enum RegistryKeyPermissionCheck
继承
RegistryKeyPermissionCheckRegistryKeyPermissionCheckRegistryKeyPermissionCheckRegistryKeyPermissionCheck

字段

Default Default Default Default 0

注册表项继承其父项的模式。The registry key inherits the mode of its parent. 除非用 ReadSubTreeReadWriteSubTree 模式打开父项,否则会在尝试访问子项或值时执行安全检查。Security checks are performed when trying to access subkeys or values, unless the parent was opened with ReadSubTree or ReadWriteSubTree mode.

ReadSubTree ReadSubTree ReadSubTree ReadSubTree 1

在访问子项或值时,不执行安全检查。Security checks are not performed when accessing subkeys or values. 除非用 ReadSubTreeReadWriteSubTree 打开父项,否则会在尝试打开当前项时执行安全检查。A security check is performed when trying to open the current key, unless the parent was opened with ReadSubTree or ReadWriteSubTree.

ReadWriteSubTree ReadWriteSubTree ReadWriteSubTree ReadWriteSubTree 2

在访问子项或值时,不执行安全检查。Security checks are not performed when accessing subkeys or values. 除非用 ReadWriteSubTree 打开父项,否则会在尝试打开当前项时执行安全检查。A security check is performed when trying to open the current key, unless the parent was opened with ReadWriteSubTree.

示例

下面的代码示例创建一个包含 100 键/值对的子项,并将其关闭。The following code example creates a subkey containing 100 key/value pairs and closes it. 该示例使用默认打开的子项,并记录读取所有值所用的时间。The example opens the subkey with Default and records the time it takes to read all the values. 本示例使用 ReadSubTree 打开的子项,然后记录读取所有值所用的时间。Then 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 System
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.
' 

注解

当应用程序将保存,或从一组子项中检索大量的注册表设置时,将执行许多冗余安全检查。When an application saves or retrieves a large number of registry settings from a set of subkeys, numerous redundant security checks are performed. 此枚举指定的密钥的安全检查时省略。This enumeration specifies when security checks on a key are to be omitted.

下表显示执行安全检查,基于打开父项和当前密钥的方式。The following table shows when security checks are performed, based on the way the parent key and the current key are opened.

父项的打开方式Parent key opened with 当前项的打开方式Current key opened with 结果Result
默认Default 默认Default 访问当前密钥中的任何值时,或尝试访问子项时,执行安全检查。A security check is performed when accessing any value in the current key, or when attempting to access a subkey. 这是.NET framework 1.0 和 1.1 版中的行为。This is the behavior in the .NET Framework versions 1.0 and 1.1.
默认Default ReadSubTreeReadSubTree 尝试打开当前项时执行安全检查。A security check is performed when trying to open the current key.
默认Default ReadWriteSubTreeReadWriteSubTree 尝试打开当前项时执行安全检查。A security check is performed when trying to open the current key.
ReadSubTreeReadSubTree 默认值或 ReadSubTreeDefault or ReadSubTree 打开当前的密钥或它的值时,会不执行任何安全检查。No security checks are performed when opening the current key or its values.
ReadSubTreeReadSubTree ReadWriteSubTreeReadWriteSubTree 尝试打开当前项时执行安全检查。A security check is performed when trying to open the current key.
ReadWriteSubTreeReadWriteSubTree 任意Any 打开当前的密钥或它的值时,会不执行任何安全检查。No security checks are performed when opening the current key or its values.

适用于