System.Security.Permissions.EnvironmentPermission Class

public sealed class EnvironmentPermission : CodeAccessPermission

Base Types

Object
  CodeAccessPermission
    EnvironmentPermission

This type implements IPermission.

Assembly

mscorlib

Library

BCL

Summary

Controls access to environment variables.

Description

[Note: EnvironmentPermission objects describe protected operations on environment variables. This permission distinguishes between the following types of access provided by EnvironmentPermissionAccess:

These access levels are independent, meaning that rights to one do not imply rights to another. For example, Write permission does not imply permission to Read . EnvironmentPermissionAccess values can be combined using a bitwise OR operator.

The Environment class is used to access environment variables, subject to the permissions defined by EnvironmentPermission. Environment variables are case-insensitive.

]

The XML encoding of a EnvironmentPermission instance is defined below in EBNF format. The following conventions are used:

The following meta-language symbols are used:

BuildVersion refers to the build version of the shipping CLI. This is specified as a dotted build number such as '2412.0' .

ECMAPubKeyToken ::= b77a5c561934e089

EnvironmentVariable refers to the name of a single environment variable, such as 'PROMPT'.

The XML encoding of an EnvironmentPermission instance is as follows:

EnvironmentPermissionXML ::=

<IPermission

class="

System.Security.Permissions.EnvironmentPermission,

mscorlib,

Version=1.0. BuildVersion,

Culture=neutral,

PublicKeyToken= ECMAPubKeyToken"

version="1"

(

Unrestricted="true"

)

|

(

(Read=" EnvironmentVariable (; EnvironmentVariable)*" )?

(Write=" EnvironmentVariable (; EnvironmentVariable)* " )?

)

/>

See Also

System.Security.Permissions Namespace

Members

EnvironmentPermission Constructors

EnvironmentPermission(System.Security.Permissions.PermissionState) Constructor
EnvironmentPermission(System.Security.Permissions.EnvironmentPermissionAccess, System.String) Constructor

EnvironmentPermission Methods

EnvironmentPermission.Copy Method
EnvironmentPermission.FromXml Method
EnvironmentPermission.Intersect Method
EnvironmentPermission.IsSubsetOf Method
EnvironmentPermission.ToXml Method
EnvironmentPermission.Union Method


EnvironmentPermission(System.Security.Permissions.PermissionState) Constructor

public EnvironmentPermission(PermissionState state);

Summary

Constructs and initializes a new instance of the EnvironmentPermission class with the specified PermissionState value.

Parameters

state
A PermissionState value.

Exceptions

Exception TypeCondition
ArgumentExceptionstate is not a valid PermissionState value.

Description

[Note: The instance returned by this constructor has either fully restricted (System.Security.Permissions.PermissionState.None) or unrestricted (System.Security.Permissions.PermissionState.Unrestricted) access to all environment variables.

]

See Also

System.Security.Permissions.EnvironmentPermission Class, System.Security.Permissions Namespace

EnvironmentPermission(System.Security.Permissions.EnvironmentPermissionAccess, System.String) Constructor

public EnvironmentPermission(EnvironmentPermissionAccess flag, string pathList);

Summary

Constructs a new instance of the EnvironmentPermission class with the specified access to the specified environment variables.

Parameters

flag
One of values defined by EnvironmentPermissionAccess.
pathList
A String containing one or more case-insensitive environment variable names separated by System.IO.Path.PathSeparator.

Exceptions

Exception TypeCondition
ArgumentNullExceptionpathList is null .

ArgumentExceptionflag specifies a value not defined in EnvironmentPermissionAccess.

Description

The specified access is applied to all environment variables in pathList.

See Also

System.Security.Permissions.EnvironmentPermission Class, System.Security.Permissions Namespace

EnvironmentPermission.Copy Method

public override IPermission Copy();

Summary

Returns a new EnvironmentPermission object containing the same values as the current instance.

Return Value

A new EnvironmentPermission containing the same values as the current instance.

Description

[Note: The object returned by this method represents the same level of access to the same environment variables as the current instance.]

This method overrides System.Security.CodeAccessPermission.Copy and is implemented to support the IPermission interface.

See Also

System.Security.Permissions.EnvironmentPermission Class, System.Security.Permissions Namespace

EnvironmentPermission.FromXml Method

public override void FromXml(SecurityElement esd);

Summary

Reconstructs the state of a EnvironmentPermission object using the specified XML encoding.

Parameters

esd
A SecurityElement instance containing the XML encoding to use to reconstruct the state of a EnvironmentPermission object.

Exceptions

Exception TypeCondition
ArgumentNullExceptionesd is null .
ArgumentExceptionesd does not contain the encoding for a EnvironmentPermission instance.

The version number of esd is not valid.

Description

The state of the current instance is changed to the state encoded in esd.

[Note: For the XML encoding for this class, see the EnvironmentPermission class page.

This method overrides System.Security.CodeAccessPermission.FromXml(System.Security.SecurityElement).

]

See Also

System.Security.Permissions.EnvironmentPermission Class, System.Security.Permissions Namespace

EnvironmentPermission.Intersect Method

public override IPermission Intersect(IPermission target);

Summary

Returns a new EnvironmentPermission object that is the intersection of the current instance and the specified object.

Parameters

target
A EnvironmentPermission instance to intersect with the current instance.

Return Value

A new EnvironmentPermission instance that represents the intersection of the current instance and target. If the intersection is empty or target is null , returns null . If the current instance is unrestricted, returns a copy of target. If target is unrestricted, returns a copy of the current instance.

Exceptions

Exception TypeCondition
ArgumentExceptiontarget is not null and is not of type EnvironmentPermission.

Description

[Note: The intersection of two permissions is a permission that secures the resources and operations secured by both permissions. Specifically, it represents the minimum permission such that any demand that passes both permissions will also pass their intersection.

This method overrides System.Security.CodeAccessPermission.Intersect(System.Security.IPermission) and is implemented to support the IPermission interface.

]

See Also

System.Security.Permissions.EnvironmentPermission Class, System.Security.Permissions Namespace

EnvironmentPermission.IsSubsetOf Method

public override bool IsSubsetOf(IPermission target);

Summary

Determines whether the current instance is a subset of the specified object.

Parameters

target
A EnvironmentPermission instance that is to be tested for the subset relationship.

Return Value

true if the current instance is a subset of target ; otherwise, false . If the current instance is unrestricted, and target is not, returns false . If target is unrestricted, returns true . If target is null and no environment variables are secured by the current instance, returns true . If target is null , and the current instance secures one or more environment variables, returns false .

Exceptions

Exception TypeCondition
ArgumentExceptiontarget is not null and is not of type EnvironmentPermission .

Description

[Note: The current instance is a subset of target if the current instance specifies a set of accesses to resources that is wholly contained by target. For example, a permission that represents read access to a file is a subset of a permission that represents read and write access to the file.

If this method returns true , the current instance describes a level of access to a set of environment variables that is also described by target.

This method overrides System.Security.CodeAccessPermission.IsSubsetOf(System.Security.IPermission) and is implemented to support the IPermission interface.

]

See Also

System.Security.Permissions.EnvironmentPermission Class, System.Security.Permissions Namespace

EnvironmentPermission.ToXml Method

public override SecurityElement ToXml();

Summary

Returns the XML encoding of the current instance.

Return Value

A SecurityElement containing the XML encoding of the state of the current instance.

Description

[Note: For the XML encoding for this class, see the EnvironmentPermission class page.

This method overrides System.Security.CodeAccessPermission.ToXml .

]

See Also

System.Security.Permissions.EnvironmentPermission Class, System.Security.Permissions Namespace

EnvironmentPermission.Union Method

public override IPermission Union(IPermission other);

Summary

Returns a new EnvironmentPermission that is the union of the current instance and the specified object.

Parameters

other
A EnvironmentPermission instance to combine with the current instance.

Return Value

A new EnvironmentPermission instance that represents the union of the current instance and other . If the current instance or other is unrestricted, returns a EnvironmentPermission instance that is unrestricted. If other is null , returns a copy of the current instance via the System.Security.IPermission.Copy method. If the current instance and other do not specify any environment variables, returns null .

Exceptions

Exception TypeCondition
ArgumentExceptionother is not null and is not of type EnvironmentPermission .

Description

[Note: The result of a call to System.Security.Permissions.EnvironmentPermission.Union(System.Security.IPermission) is a permission that represents the access to environment variables represented by the current instance as well as the access to environment variables represented by other. Any demand that passes either the current instance or other passes their union.

This method overrides System.Security.CodeAccessPermission.Union(System.Security.IPermission) and is implemented to support the IPermission interface.

]

See Also

System.Security.Permissions.EnvironmentPermission Class, System.Security.Permissions Namespace