Share via


RegistryPermission 类

控制访问注册表变量的能力。无法继承此类。

**命名空间:**System.Security.Permissions
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class RegistryPermission
    Inherits CodeAccessPermission
    Implements IUnrestrictedPermission
用法
Dim instance As RegistryPermission
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public sealed class RegistryPermission : CodeAccessPermission, IUnrestrictedPermission
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class RegistryPermission sealed : public CodeAccessPermission, IUnrestrictedPermission
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class RegistryPermission extends CodeAccessPermission implements IUnrestrictedPermission
SerializableAttribute 
ComVisibleAttribute(true) 
public final class RegistryPermission extends CodeAccessPermission implements IUnrestrictedPermission

备注

RegistryPermission 描述注册表变量上的受保护操作。注册表变量不应存储在没有 RegistryPermission 的代码也能访问注册表的内存位置上。如果注册表对象传递到不受信任的调用方,则它可能会被误用。

允许的注册表访问类型由 RegistryPermissionAccess 定义。如果需要一个以上的访问类型,可以使用按位“或”操作组合这些类型,如下面的代码示例所示。

注册表权限按照规范的绝对路径定义,并且应始终通过规范的路径名进行检查。键访问权意味着可以访问该键包含的所有值及其下属的所有变量。

警告

RegistryPermission 将对所有路径的权限授予给一个键,包括 HKEY_CURRENT_USER 和 HKEY_USERS。若要 Deny 对某个键的访问,则必须 Deny 对该键所有可能的路径。例如,若要 Deny 对 HKEY_CURRENT_USER\Software\Microsoft\Cryptography 的访问,则必须 Deny HKEY_CURRENT_USER\Software\Microsoft\Cryptography、HKEY_USERS\.......\Software\Microsoft\Cryptography 以及任何可以用于访问该键的其他路径。处理多路径的更好方法是结合使用 PermitOnlyDeny。有关此主题以及如何结合使用 PermitOnlyDeny 的更多信息,请参见 使用 Deny 方法 中的“使用拒绝的规范化问题”。

示例

在下面的代码示例中,RegistryPermissionf 表示从 CentralProcessor 项读取值的权限。ReadWriteRegistryPermissionAccess 枚举值。

Dim f As New RegistryPermission( _
RegistryPermissionAccess.Read, _
"HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0")
RegistryPermission f = new RegistryPermission(
RegistryPermissionAccess.Read, 
"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
RegistryPermission^ f = gcnew RegistryPermission(
   RegistryPermissionAccess::Read,
   "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0" );
RegistryPermission f =  
    new RegistryPermission(RegistryPermissionAccess.Read,
        "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\"
        + "System\\CentralProcessor\\0");

下面的代码示例将读取和写入 FloatingPointProcessor 项的权限添加到 RegistryPermissionf 中。

f.AddPathList( _
RegistryPermissionAccess.Write Or RegistryPermissionAccess.Read, _
"HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\FloatingPointProcessor\0")
f.AddPathList(
RegistryPermissionAccess.Write | RegistryPermissionAccess.Read,
"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor\\0");
f->AddPathList(
   (RegistryPermissionAccess) (RegistryPermissionAccess::Write | RegistryPermissionAccess::Read),
   "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor\\0" );
f.AddPathList(RegistryPermissionAccess.Write |
    RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\HARDWARE\\"
    + "DESCRIPTION\\System\\FloatingPointProcessor\\0");

RegistryPermission f 现在表示对 CentralProcessor 项的读权限和对 FloatingPointProcessor 项的读写权限。

下面的代码示例演示 RegistryPermission 方法的行为。该示例的目的是演示方法的结果,而不演示如何使用这些方法。

' This sample demonstrates the IsSubsetOf, Union, Intersect, Copy, ToXml, FromXml
' GetPathList, AddPathList, and SetPathList methods
' of the RegistryPermission class.

Imports System
Imports System.Security
Imports System.Security.Permissions
Imports System.Collections

Public Class RegistryPermissionDemo
    Private readPerm1 As New RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0")
    Private readPerm2 As New RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION")
    Private readPerm3 As New RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\FloatingPointProcessor\0")
    Private createPerm1 As New RegistryPermission(RegistryPermissionAccess.Create, "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0")
    Private readPerm4 As IPermission

    ' IsSubsetOf determines whether the current permission is a subset of the specified permission.
    Private Function IsSubsetOfDemo() As Boolean

        Dim returnValue As Boolean = True

        If readPerm1.IsSubsetOf(readPerm2) Then

            Console.WriteLine(readPerm1.GetPathList(RegistryPermissionAccess.Read) + vbLf + " is a subset of " + readPerm2.GetPathList(RegistryPermissionAccess.Read) + vbLf)
        Else
            Console.WriteLine(readPerm1.GetPathList(RegistryPermissionAccess.Read) + vbLf + " is not a subset of " + readPerm2.GetPathList(RegistryPermissionAccess.Read) + vbLf)
        End If
        If createPerm1.IsSubsetOf(readPerm1) Then

            Console.WriteLine("RegistryPermissionAccess.Create" + vbLf + " is a subset of " + "RegistryPermissionAccess.Read" + vbLf)
        Else
            Console.WriteLine("RegistryPermissionAccess.Create" + vbLf + " is not a subset of " + "RegistryPermissionAccess.Read" + vbLf)
        End If

        Return returnValue

    End Function 'IsSubsetOfDemo

    ' Union creates a new permission that is the union of the current permission and
    ' the specified permission.
    Private Function UnionDemo() As Boolean

        Dim returnValue As Boolean = True
        readPerm3 = CType(readPerm1.Union(readPerm2), RegistryPermission)

        If readPerm3 Is Nothing Then
            Console.WriteLine("The union of " + vbLf + readPerm1.GetPathList(RegistryPermissionAccess.Read) + " " + vbLf + "and " + readPerm2.GetPathList(RegistryPermissionAccess.Read) + " is null.")
        Else
            Console.WriteLine("The union of " + vbLf + readPerm1.GetPathList(RegistryPermissionAccess.Read) + " " + vbLf + "and " + readPerm2.GetPathList(RegistryPermissionAccess.Read) + " = " + vbLf + vbTab + CType(readPerm3, RegistryPermission).GetPathList(RegistryPermissionAccess.Read).ToString())
        End If

        Return returnValue

    End Function 'UnionDemo

    ' Intersect creates and returns a new permission that is the intersection of the
    ' current permission and the permission specified.
    Private Function IntersectDemo() As Boolean

        Dim returnValue As Boolean = True

        readPerm3 = CType(readPerm1.Intersect(readPerm2), RegistryPermission)
        If Not (readPerm3 Is Nothing) AndAlso Not (readPerm3.GetPathList(RegistryPermissionAccess.Read) Is Nothing) Then

            Console.WriteLine("The intersection of " + vbLf + readPerm1.GetPathList(RegistryPermissionAccess.Read) + " " + vbLf + "and " + readPerm2.GetPathList(RegistryPermissionAccess.Read) + " = " + vbLf + vbTab + CType(readPerm3, RegistryPermission).GetPathList(RegistryPermissionAccess.Read).ToString())
        Else
            Console.WriteLine("The intersection of " + vbLf + readPerm2.GetPathList(RegistryPermissionAccess.Read) + " " + vbLf + "and " + readPerm2.GetPathList(RegistryPermissionAccess.Read) + " is null. ")
        End If

        Return returnValue

    End Function 'IntersectDemo

    'Copy creates and returns an identical copy of the current permission.
    Private Function CopyDemo() As Boolean

        Dim returnValue As Boolean = True
        readPerm4 = CType(readPerm1.Copy(), RegistryPermission)
        If Not (readPerm4 Is Nothing) Then
            Console.WriteLine("Result of copy = " + readPerm4.ToXml().ToString() + vbLf)
        Else
            Console.WriteLine("Result of copy is null. " + vbLf)
        End If
        Return returnValue

    End Function 'CopyDemo

    ' ToXml creates an XML encoding of the permission and its current state; FromXml
    ' reconstructs a permission with the specified state from the XML encoding.
    Private Function ToFromXmlDemo() As Boolean

        Dim returnValue As Boolean = True
        readPerm2 = New RegistryPermission(PermissionState.None)
        readPerm2.FromXml(readPerm1.ToXml())
        Console.WriteLine("Result of ToFromXml = " + readPerm2.ToString() + vbLf)

        Return returnValue

    End Function 'ToFromXmlDemo

    ' AddPathList adds access for the specified registry variables to the existing state of the permission.
    ' SetPathList sets new access for the specified registry variable names to the existing state of the permission.
    ' GetPathList gets paths for all registry variables with the specified RegistryPermissionAccess.
    Private Function SetGetPathListDemo() As Boolean
        Try
            Console.WriteLine("********************************************************" + vbLf)

            Dim readPerm1 As RegistryPermission
            Console.WriteLine("Creating RegistryPermission with AllAccess rights for 'HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0'")
            readPerm1 = New RegistryPermission(RegistryPermissionAccess.AllAccess, "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0")
            Console.WriteLine("Adding 'HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION' to the write access list, " + "and " + vbLf + " 'HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\FloatingPointProcessor\0' " + "to the read access list.")
            readPerm1.AddPathList(RegistryPermissionAccess.Write, "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION")
            readPerm1.AddPathList(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\FloatingPointProcessor\0")
            Console.WriteLine("Read access list before SetPathList = " + readPerm1.GetPathList(RegistryPermissionAccess.Read))
            Console.WriteLine("Setting read access rights to " + vbLf + "'HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0'")
            readPerm1.SetPathList(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0")
            Console.WriteLine("Read access list after SetPathList = " + vbLf + readPerm1.GetPathList(RegistryPermissionAccess.Read))
            Console.WriteLine("Write access = " + vbLf + readPerm1.GetPathList(RegistryPermissionAccess.Write))
            Console.WriteLine("Write access Registry variables = " + vbLf + readPerm1.GetPathList(RegistryPermissionAccess.AllAccess))
        Catch e As ArgumentException
            ' RegistryPermissionAccess.AllAccess can not be used as a parameter for GetPathList.
            Console.WriteLine("An ArgumentException occured as a result of using AllAccess. " + _
            "AllAccess cannot be used as a parameter in GetPathList because it represents more than one " + _
            "type of registry variable access : " + vbLf + e.Message)
        End Try

        Return True

    End Function 'SetGetPathListDemo

    ' Invoke all demos.
    Public Function RunDemo() As Boolean

        Dim ret As Boolean = True
        Dim retTmp As Boolean
        ' Call IsSubset demo.
        If IsSubsetOfDemo() Then
            Console.Out.WriteLine("IsSubset demo completed successfully.")
        Else
            Console.Out.WriteLine("IsSubset demo failed.")
        End If
        ret = retTmp AndAlso ret

        ' Call the Union demo.
        retTmp = UnionDemo()
        If retTmp Then
            Console.Out.WriteLine("Union demo completed successfully.")
        Else
            Console.Out.WriteLine("Union demo failed.")
        End If
        ret = retTmp AndAlso ret

        ' Call the intersect demo.
        retTmp = UnionDemo()
        If retTmp Then
            Console.Out.WriteLine("Intersect demo completed successfully.")
        Else
            Console.Out.WriteLine("Intersect demo failed.")
        End If
        ret = retTmp AndAlso ret


        ' Call the Copy demo.
        retTmp = CopyDemo()
        If retTmp Then
            Console.Out.WriteLine("Copy demo completed successfully.")
        Else
            Console.Out.WriteLine("Copy demo failed.")
        End If
        ret = retTmp AndAlso ret

        ' Call the ToFromXml demo.
        retTmp = ToFromXmlDemo()
        If retTmp Then
            Console.Out.WriteLine("ToFromXml demo completed successfully.")
        Else
            Console.Out.WriteLine("ToFromXml demo failed.")
        End If
        ret = retTmp AndAlso ret

        ' Call the GetPathList demo.
        retTmp = SetGetPathListDemo()
        If retTmp Then
            Console.Out.WriteLine("SetGetPathList demo completed successfully.")
        Else
            Console.Out.WriteLine("SetGetPathList demo failed.")
        End If
        ret = retTmp AndAlso ret

        Return ret

    End Function 'RunDemo

    ' Test harness.
    Public Shared Sub Main(ByVal args() As String)
        Try
            Dim democase As New RegistryPermissionDemo()
            Dim ret As Boolean = democase.RunDemo()
            If ret Then
                Console.Out.WriteLine("The RegisterPermission demo completed successfully.")
                Console.Out.WriteLine("Press the Enter key to exit.")
                Dim consoleInput As String = Console.ReadLine()
                System.Environment.ExitCode = 100
            Else
                Console.Out.WriteLine("The RegisterPermission demo failed")
                Console.Out.WriteLine("Press the Enter key to exit.")
                Dim consoleInput As String = Console.ReadLine()
                System.Environment.ExitCode = 101
            End If
        Catch e As Exception
            Console.Out.WriteLine("The RegisterPermission demo failed")
            Console.WriteLine(e.ToString())
            Console.Out.WriteLine("Press the Enter key to exit.")
            Dim consoleInput As String = Console.ReadLine()
            System.Environment.ExitCode = 101
        End Try

    End Sub 'Main
End Class 'RegistryPermissionDemo
// This sample demonstrates the IsSubsetOf, Union, Intersect, Copy, ToXml, FromXml
// GetPathList, AddPathList, and SetPathList methods
// of the RegistryPermission class.


using System;
using System.Security;
using System.Security.Permissions;
using System.Collections;

[assembly: CLSCompliant(true)]

public class RegistryPermissionDemo
{
    RegistryPermission readPerm1 = new RegistryPermission(RegistryPermissionAccess.Read,
        "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
    RegistryPermission readPerm2 = new RegistryPermission(RegistryPermissionAccess.Read,
       "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION");
    RegistryPermission readPerm3 = new RegistryPermission(RegistryPermissionAccess.Read,
    "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor\\0");
    RegistryPermission createPerm1 = new RegistryPermission(RegistryPermissionAccess.Create,
        "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
    IPermission readPerm4;

    // IsSubsetOf determines whether the current permission is a subset of the specified permission.
    private bool IsSubsetOfDemo()
    {

        bool returnValue = true;

        if (readPerm1.IsSubsetOf(readPerm2))
        {

            Console.WriteLine(readPerm1.GetPathList(RegistryPermissionAccess.Read) +
                "\n is a subset of " + readPerm2.GetPathList(RegistryPermissionAccess.Read) + "\n");
        }
        else
        {
            Console.WriteLine(readPerm1.GetPathList(RegistryPermissionAccess.Read) +
                "\n is not a subset of " + readPerm2.GetPathList(RegistryPermissionAccess.Read) + "\n");
        }
        if (createPerm1.IsSubsetOf(readPerm1))
        {

            Console.WriteLine("RegistryPermissionAccess.Create" +
                "\n is a subset of " + "RegistryPermissionAccess.Read" + "\n");
        }
        else
        {
            Console.WriteLine("RegistryPermissionAccess.Create" +
                "\n is not a subset of " + "RegistryPermissionAccess.Read" + "\n");
        }

        return returnValue;
    }
    // Union creates a new permission that is the union of the current permission and
    // the specified permission.
    private bool UnionDemo()
    {

        bool returnValue = true;
        readPerm3 = (RegistryPermission)readPerm1.Union(readPerm2);

        if (readPerm3 == null)
        {
            Console.WriteLine("The union of \n" +
                readPerm1.GetPathList(RegistryPermissionAccess.Read) + " \nand "
                + readPerm2.GetPathList(RegistryPermissionAccess.Read) + " is null.");
        }
        else
        {
            Console.WriteLine("The union of \n" + readPerm1.GetPathList(RegistryPermissionAccess.Read) +
                " \nand " + readPerm2.GetPathList(RegistryPermissionAccess.Read) + " = \n\t"
                + ((RegistryPermission)readPerm3).GetPathList(RegistryPermissionAccess.Read).ToString());
        }

        return returnValue;

    }
    // Intersect creates and returns a new permission that is the intersection of the
    // current permission and the permission specified.
    private bool IntersectDemo()
    {

        bool returnValue = true;

        readPerm3 = (RegistryPermission)readPerm1.Intersect(readPerm2);
        if (readPerm3 != null && readPerm3.GetPathList(RegistryPermissionAccess.Read) != null)
        {

            Console.WriteLine("The intersection of \n" + readPerm1.GetPathList(RegistryPermissionAccess.Read)
                + " \nand " + readPerm2.GetPathList(RegistryPermissionAccess.Read) + " = \n\t"
                + ((RegistryPermission)readPerm3).GetPathList(RegistryPermissionAccess.Read).ToString());
        }
        else
        {
            Console.WriteLine("The intersection of \n" + readPerm2.GetPathList(RegistryPermissionAccess.Read)
                + " \nand " + readPerm2.GetPathList(RegistryPermissionAccess.Read) + " is null. ");
        }

        return returnValue;

    }
    //Copy creates and returns an identical copy of the current permission.
    private bool CopyDemo()
    {

        bool returnValue = true;
        readPerm4 = (RegistryPermission)readPerm1.Copy();
        if (readPerm4 != null)
        {
            Console.WriteLine("Result of copy = " + readPerm4.ToString() + "\n");
        }
        else
        {
            Console.WriteLine("Result of copy is null. \n");
        }
        return returnValue;
    }
    // ToXml creates an XML encoding of the permission and its current state; FromXml
    // reconstructs a permission with the specified state from the XML encoding.
    private bool ToFromXmlDemo()
    {

        bool returnValue = true;
        readPerm2 = new RegistryPermission(PermissionState.None);
        readPerm2.FromXml(readPerm1.ToXml());
        Console.WriteLine("Result of ToFromXml = " + readPerm2.ToString() + "\n");

        return returnValue;

    }
    // AddPathList adds access for the specified registry variables to the existing state of the permission.
    // SetPathList sets new access for the specified registry variable names to the existing state of the permission.
    // GetPathList gets paths for all registry variables with the specified RegistryPermissionAccess.
    private bool SetGetPathListDemo()
    {
        try
        {
            Console.WriteLine("********************************************************\n");

            RegistryPermission readPerm1;
            Console.WriteLine("Creating RegistryPermission with AllAccess rights for 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0'");
            readPerm1 = new RegistryPermission(RegistryPermissionAccess.AllAccess, "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
            Console.WriteLine("Adding 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION' to the write access list, "
                + "and \n 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor\\0' "
                + "to the read access list.");
            readPerm1.AddPathList(RegistryPermissionAccess.Write, "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION");
            readPerm1.AddPathList(RegistryPermissionAccess.Read,
                "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor\\0");
            Console.WriteLine("Read access list before SetPathList = " +
                readPerm1.GetPathList(RegistryPermissionAccess.Read));
            Console.WriteLine("Setting read access rights to \n'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0'");
            readPerm1.SetPathList(RegistryPermissionAccess.Read,
                "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
            Console.WriteLine("Read access list after SetPathList = \n" +
                readPerm1.GetPathList(RegistryPermissionAccess.Read));
            Console.WriteLine("Write access = \n" +
                readPerm1.GetPathList(RegistryPermissionAccess.Write));
            Console.WriteLine("Write access Registry variables = \n" +
                readPerm1.GetPathList(RegistryPermissionAccess.AllAccess));
        }
        catch (ArgumentException e)
        {
            // RegistryPermissionAccess.AllAccess can not be used as a parameter for GetPathList.
            Console.WriteLine("An ArgumentException occured as a result of using AllAccess. "
                + "AllAccess cannot be used as a parameter in GetPathList because it represents more than one "
                + "type of registry variable access : \n" + e);
        }

        return true;
    }
    // Invoke all demos.
    public bool RunDemo()
    {

        bool ret = true;
        bool retTmp;
        // Call IsSubset demo.
        if (retTmp = IsSubsetOfDemo()) Console.Out.WriteLine("IsSubset demo completed successfully.");
        else Console.Out.WriteLine("IsSubset demo failed.");
        ret = retTmp && ret;

        // Call the Union demo.
        if (retTmp = UnionDemo()) Console.Out.WriteLine("Union demo completed successfully.");
        else Console.Out.WriteLine("Union demo failed.");
        ret = retTmp && ret;

        // Call the intersect demo.
        if (retTmp = IntersectDemo()) Console.Out.WriteLine("Intersect demo completed successfully.");
        else Console.Out.WriteLine("Intersect demo failed.");
        ret = retTmp && ret;


        // Call the Copy demo.
        if (retTmp = CopyDemo()) Console.Out.WriteLine("Copy demo completed successfully.");
        else Console.Out.WriteLine("Copy demo failed.");
        ret = retTmp && ret;

        // Call the ToFromXml demo.
        if (retTmp = ToFromXmlDemo()) Console.Out.WriteLine("ToFromXml demo completed successfully.");
        else Console.Out.WriteLine("ToFromXml demo failed.");
        ret = retTmp && ret;

        // Call the GetPathList demo.
        if (retTmp = SetGetPathListDemo()) Console.Out.WriteLine("SetGetPathList demo completed successfully.");
        else Console.Out.WriteLine("SetGetPathList demo failed.");
        ret = retTmp && ret;

        return (ret);

    }
    // Test harness.
    public static void Main(String[] args)
    {
        try
        {
            RegistryPermissionDemo democase = new RegistryPermissionDemo();
            bool ret = democase.RunDemo();
            if (ret)
            {
                Console.Out.WriteLine("The RegisterPermission demo completed successfully.");
                Console.Out.WriteLine("Press the Enter key to exit.");
                string consoleInput = Console.ReadLine();
                System.Environment.ExitCode = 100;
            }
            else
            {
                Console.Out.WriteLine("The RegisterPermission demo failed");
                Console.Out.WriteLine("Press the Enter key to exit.");
                string consoleInput = Console.ReadLine();
                System.Environment.ExitCode = 101;
            }
        }
        catch (Exception e)
        {
            Console.Out.WriteLine("The RegisterPermission demo failed");
            Console.WriteLine(e.ToString());
            Console.Out.WriteLine("Press the Enter key to exit.");
            string consoleInput = Console.ReadLine();
            System.Environment.ExitCode = 101;
        }
    }
}

继承层次结构

System.Object
   System.Security.CodeAccessPermission
    System.Security.Permissions.RegistryPermission

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

RegistryPermission 成员
System.Security.Permissions 命名空间
RegistryPermissionAttribute
RegistryPermissionAccess

其他资源

安全权限
请求权限