RegistryPermission 类

定义

控制访问注册表变量的能力。Controls the ability to access registry variables. 无法继承此类。This class cannot be inherited.

public ref class RegistryPermission sealed : System::Security::CodeAccessPermission, System::Security::Permissions::IUnrestrictedPermission
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public sealed class RegistryPermission : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
type RegistryPermission = class
    inherit CodeAccessPermission
    interface IUnrestrictedPermission
Public NotInheritable Class RegistryPermission
Inherits CodeAccessPermission
Implements IUnrestrictedPermission
继承
RegistryPermission
属性
实现

注解

RegistryPermission 描述注册表变量的受保护操作。RegistryPermission describes protected operations on registry variables. 不应将注册表变量存储在某些内存位置,在这些位置,不具有 RegistryPermission 的代码可访问这些变量。Registry variables should not be stored in memory locations where code without RegistryPermission can access them. 如果将注册表对象传递到不受信任的调用方,则可能会被误用。If the registry object is passed to an untrusted caller it can be misused.

允许的注册表访问类型由 RegistryPermissionAccess定义。The allowed registry access types are defined by RegistryPermissionAccess. 如果需要多个类型的访问,则可以使用按位 "或" 运算将它们组合起来,如下面的代码示例中所示。If more than one type of access is desired, they can be combined using the bitwise OR operation as shown in the code sample that follows.

注册表权限是根据规范绝对路径定义的;检查应始终带有规范路径名。Registry permission is defined in terms of canonical absolute paths; checks should always be made with canonical pathnames. 密钥访问权限意味着可以访问其包含的所有值以及它所包含的所有变量。Key access implies access to all values it contains and all variables under it.

备注

.NET Framework 4.NET Framework 4之前的 .NET Framework 版本中,你可以使用 CodeAccessPermission.Deny 方法,以防止无意中通过受信任代码访问系统资源。In versions of the .NET Framework before the .NET Framework 4.NET Framework 4, you could use the CodeAccessPermission.Deny method to prevent inadvertent access to system resources by trusted code. Deny 现已过时,并且现在仅由为程序集授予的权限集来确定对资源的访问权限。Deny is now obsolete, and access to resources is now determined solely by the granted permission set for an assembly. 若要限制对文件的访问,必须在沙盒中运行部分受信任的代码,并仅向该代码允许访问的资源分配权限。To limit access to files, you must run partially trusted code in a sandbox and assign it permissions only to resources that the code is allowed to access. 有关在沙盒中运行应用程序的信息,请参阅如何:在沙盒中运行部分受信任的代码For information about running an application in a sandbox, see How to: Run Partially Trusted Code in a Sandbox.

构造函数

RegistryPermission(PermissionState)

根据指定,使用完全受限制或不受限制的权限初始化 RegistryPermission 类的新实例。Initializes a new instance of the RegistryPermission class with either fully restricted or unrestricted permission as specified.

RegistryPermission(RegistryPermissionAccess, AccessControlActions, String)

使用对指定注册表变量的指定访问权限和对注册表控制信息的指定访问权限,初始化 RegistryPermission 类的新实例。Initializes a new instance of the RegistryPermission class with the specified access to the specified registry variables and the specified access rights to registry control information.

RegistryPermission(RegistryPermissionAccess, String)

通过对指定注册表变量的指定访问权限初始化 RegistryPermission 类的新实例。Initializes a new instance of the RegistryPermission class with the specified access to the specified registry variables.

方法

AddPathList(RegistryPermissionAccess, AccessControlActions, String)

将指定注册表变量的访问权限添加到现有的权限状态中,同时指定注册表权限访问和访问控制操作。Adds access for the specified registry variables to the existing state of the permission, specifying registry permission access and access control actions.

AddPathList(RegistryPermissionAccess, String)

将指定的注册表变量的访问权限添加到现有的权限状态中。Adds access for the specified registry variables to the existing state of the permission.

Assert()

声明调用代码能够通过调用此方法的代码,访问受权限请求保护的资源,即使未对堆栈中处于较高位置的调用方授予访问该资源的权限。Declares that the calling code can access the resource protected by a permission demand through the code that calls this method, even if callers higher in the stack have not been granted permission to access the resource. 使用 Assert() 会引起安全问题。Using Assert() can create security issues.

(继承自 CodeAccessPermission)
Copy()

创建并返回当前权限的相同副本。Creates and returns an identical copy of the current permission.

Demand()

如果未对调用堆栈中处于较高位置的所有调用方授予当前实例所指定的权限,则在运行时强制 SecurityExceptionForces a SecurityException at run time if all callers higher in the call stack have not been granted the permission specified by the current instance.

(继承自 CodeAccessPermission)
Deny()

防止处于调用堆栈较高位置的调用函数使用可以调用此方法来访问当前实例指定资源的代码。Prevents callers higher in the call stack from using the code that calls this method to access the resource specified by the current instance.

(继承自 CodeAccessPermission)
Equals(Object)

确定指定的 CodeAccessPermission 对象是否等于当前的 CodeAccessPermissionDetermines whether the specified CodeAccessPermission object is equal to the current CodeAccessPermission.

(继承自 CodeAccessPermission)
FromXml(SecurityElement)

从 XML 编码重新构造具有指定状态的权限。Reconstructs a permission with a specified state from an XML encoding.

GetHashCode()

获取 CodeAccessPermission 对象的哈希代码,此代码适合在哈希算法和数据结构(例如哈希表)中使用。Gets a hash code for the CodeAccessPermission object that is suitable for use in hashing algorithms and data structures such as a hash table.

(继承自 CodeAccessPermission)
GetPathList(RegistryPermissionAccess)

获取具有指定 RegistryPermissionAccess 的所有注册表变量的路径。Gets paths for all registry variables with the specified RegistryPermissionAccess.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
Intersect(IPermission)

创建并返回一个权限,该权限是当前权限与指定权限的交集。Creates and returns a permission that is the intersection of the current permission and the specified permission.

IsSubsetOf(IPermission)

确定当前权限是否为指定权限的子集。Determines whether the current permission is a subset of the specified permission.

IsUnrestricted()

返回一个值,该值指示当前权限是否不受限制。Returns a value indicating whether the current permission is unrestricted.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
PermitOnly()

防止处于调用堆栈较高位置的调用函数使用此代码,此代码将调用此方法来访问除当前实例指定的资源以外的所有资源。Prevents callers higher in the call stack from using the code that calls this method to access all resources except for the resource specified by the current instance.

(继承自 CodeAccessPermission)
SetPathList(RegistryPermissionAccess, String)

将指定的注册表变量名称的新访问权限设置为现有的权限状态。Sets new access for the specified registry variable names to the existing state of the permission.

ToString()

创建并返回当前权限对象的字符串表示形式。Creates and returns a string representation of the current permission object.

(继承自 CodeAccessPermission)
ToXml()

创建权限及其当前状态的 XML 编码。Creates an XML encoding of the permission and its current state.

Union(IPermission)

创建一个权限,该权限是当前权限与指定权限的并集。Creates a permission that is the union of the current permission and the specified permission.

显式接口实现

IPermission.Demand() (继承自 CodeAccessPermission)
IStackWalk.Assert() (继承自 CodeAccessPermission)
IStackWalk.Demand() (继承自 CodeAccessPermission)
IStackWalk.Deny() (继承自 CodeAccessPermission)
IStackWalk.PermitOnly() (继承自 CodeAccessPermission)

适用于

另请参阅