This documentation is archived and is not being maintained.

EnvironmentPermission Constructor

.NET Framework 1.1

Initializes a new instance of the EnvironmentPermission class.

Overload List

Initializes a new instance of the EnvironmentPermission class with either restricted or unrestricted permission as specified.

[Visual Basic] Public Sub New(PermissionState)
[C#] public EnvironmentPermission(PermissionState);
[C++] public: EnvironmentPermission(PermissionState);
[JScript] public function EnvironmentPermission(PermissionState);

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

[Visual Basic] Public Sub New(EnvironmentPermissionAccess, String)
[C#] public EnvironmentPermission(EnvironmentPermissionAccess, string);
[C++] public: EnvironmentPermission(EnvironmentPermissionAccess, String*);
[JScript] public function EnvironmentPermission(EnvironmentPermissionAccess, String);

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the EnvironmentPermission constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
' Create an EnvironmentPermission using a given EnvironmentPermissionAccess.
Public Function CreateEnv(ByRef envPerm As EnvironmentPermission, ByRef env As String, ByVal epa As EnvironmentPermissionAccess) As Boolean


    If envIndex = myEnv.Length Then
        envPerm = New EnvironmentPermission(PermissionState.None)
        env = ""
        envIndex = envIndex + 1
        Return True
    End If
    If envIndex > myEnv.Length Then
        envPerm = Nothing
        env = ""
        Return False
    End If

    env = myEnv(envIndex)
    envIndex = envIndex + 1

    Try
        envPerm = New EnvironmentPermission(epa, env)
        Return True
    Catch e As Exception
        Console.WriteLine(("Cannot create EnvironmentPermission : " & env & " " & e.ToString()))
        envPerm = New EnvironmentPermission(PermissionState.None)
        env = ""
        Return True
    End Try
End Function 'CreateEnv

[C#] 
// Create an EnvironmentPermission using a given EnvironmentPermissionAccess.
    public bool CreateEnv(out EnvironmentPermission envPerm, out string env, EnvironmentPermissionAccess epa)
    {


        if(envIndex == myEnv.Length) 
        {
            envPerm = new EnvironmentPermission(PermissionState.None);
            env="";
            envIndex++;
            return true;

        }
        if(envIndex > myEnv.Length)
        {
            envPerm = null;
            env = "";
            return false;
        }

        env = myEnv[envIndex++];

        try
        {
            envPerm = new EnvironmentPermission(epa, env);
            return true;
        } 
        catch(Exception e)
        {
            Console.WriteLine("Cannot create EnvironmentPermission : " + env +" "+e);
            envPerm = new EnvironmentPermission(PermissionState.None);
            env="";
            return true;
        }
    }

[C++] 
// Create an EnvironmentPermission using a given EnvironmentPermissionAccess.
public:
bool CreateEnv(
   [Out] EnvironmentPermission** envPerm,
   [Out] String** env, EnvironmentPermissionAccess epa) {
   if (envIndex == myEnv->Length) {
      *envPerm = new EnvironmentPermission(PermissionState::None);
      *env=S"";
      envIndex++;
      return true;

   }
   if (envIndex > myEnv->Length) {
      *envPerm = 0;
      *env = S"";
      return false;
   }

   *env = myEnv[envIndex++];

   try {
      *envPerm = new EnvironmentPermission(epa, *env);
      return true;
   } catch (Exception* e) {
      Console::WriteLine(S"Cannot create EnvironmentPermission : {0}{1}", *env, e);
      *envPerm = new EnvironmentPermission(PermissionState::None);
      *env=S"";
      return true;
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

EnvironmentPermission Class | EnvironmentPermission Members | System.Security.Permissions Namespace

Show: