Export (0) Print
Expand All

EnvironmentPermission.AddPathList Method

Adds access for the specified environment variables to the existing state of the permission.

[Visual Basic]
Public Sub AddPathList( _
   ByVal flag As EnvironmentPermissionAccess, _
   ByVal pathList As String _
)
[C#]
public void AddPathList(
 EnvironmentPermissionAccess flag,
 string pathList
);
[C++]
public: void AddPathList(
 EnvironmentPermissionAccess flag,
 String* pathList
);
[JScript]
public function AddPathList(
   flag : EnvironmentPermissionAccess,
 pathList : String
);

Parameters

flag
One of the EnvironmentPermissionAccess values.
pathList
A list of environment variables (semicolon-separated).

Exceptions

Exception Type Condition
ArgumentNullException The pathList parameter is a null reference (Nothing in Visual Basic).
ArgumentException The flag parameter is not a valid value of EnvironmentPermissionAccess.

Remarks

Use this method to modify environment variable access by adding to the state of the current permission.

Example

[Visual Basic] 
' AddPathList adds access for the specified environment variables to the existing state of the permission.
' SetPathList Sets the specified access to the specified environment variables to the existing state 
' of the permission.
' GetPathList gets all environment variables with the specified EnvironmentPermissionAccess.
Private Function SetGetPathListDemo() As Boolean
    Try
        Console.WriteLine("********************************************************" & ControlChars.Lf)

        Dim envPerm1 As EnvironmentPermission
        Console.WriteLine("Creating an EnvironmentPermission with AllAccess rights for 'TMP'")
        envPerm1 = New EnvironmentPermission(EnvironmentPermissionAccess.AllAccess, "TMP")
        Console.WriteLine("Adding 'TEMP' to the write access list, and 'windir' to the read access list.")
        envPerm1.AddPathList(EnvironmentPermissionAccess.Write, "TEMP")
        envPerm1.AddPathList(EnvironmentPermissionAccess.Read, "windir")
        Console.WriteLine(("Read access list before SetPathList = " & envPerm1.GetPathList(EnvironmentPermissionAccess.Read)))
        Console.WriteLine("Setting read access to 'TMP'")
        envPerm1.SetPathList(EnvironmentPermissionAccess.Read, "TMP")
        Console.WriteLine(("Read access list after SetPathList = " & envPerm1.GetPathList(EnvironmentPermissionAccess.Read)))
        Console.WriteLine(("Write access list = " & envPerm1.GetPathList(EnvironmentPermissionAccess.Write)))
        Console.WriteLine(("Write access environment variables = " & envPerm1.GetPathList(EnvironmentPermissionAccess.AllAccess)))
    Catch e As ArgumentException
        ' EnvironmentPermissionAccess.AllAccess cannot be used as a parameter for GetPathList.
        Console.WriteLine(("An ArgumentException occurred as a result of using AllAccess. " _
        & " This property cannot be used as a parameter in GetPathList, because it represents " _
        & "more than one type of environment variable : " & ControlChars.Lf & e.ToString()))
    End Try

    Return True
End Function 'SetGetPathListDemo


[C#] 
// AddPathList adds access for the specified environment variables to the existing state of the permission.
// SetPathList Sets the specified access to the specified environment variables to the existing state 
// of the permission.
// GetPathList gets all environment variables with the specified EnvironmentPermissionAccess.
private bool SetGetPathListDemo()
{
    try
    {
        Console.WriteLine("********************************************************\n");

        EnvironmentPermission envPerm1;
        Console.WriteLine("Creating an EnvironmentPermission with AllAccess rights for 'TMP'");
        envPerm1 = new EnvironmentPermission(EnvironmentPermissionAccess.AllAccess, "TMP");
        Console.WriteLine("Adding 'TEMP' to the write access list, and 'windir' to the read access list.");
        envPerm1.AddPathList(EnvironmentPermissionAccess.Write, "TEMP");
        envPerm1.AddPathList(EnvironmentPermissionAccess.Read, "windir");
        Console.WriteLine("Read access list before SetPathList = " 
            + envPerm1.GetPathList(EnvironmentPermissionAccess.Read));
        Console.WriteLine("Setting read access to 'TMP'");
        envPerm1.SetPathList(EnvironmentPermissionAccess.Read, "TMP");
        Console.WriteLine("Read access list after SetPathList = " 
            + envPerm1.GetPathList(EnvironmentPermissionAccess.Read));
        Console.WriteLine("Write access list = " + envPerm1.GetPathList(EnvironmentPermissionAccess.Write));
        Console.WriteLine("Write access environment variables = " 
            + envPerm1.GetPathList(EnvironmentPermissionAccess.AllAccess));
    }
    catch (ArgumentException e)
    {
        // EnvironmentPermissionAccess.AllAccess cannot be used as a parameter for GetPathList.
        Console.WriteLine("An ArgumentException occurred as a result of using AllAccess. " 
            + " This property cannot be used as a parameter in GetPathList, because it represents " 
            + "more than one type of environment variable : \n" + e);
    }

    return true;        
}

[C++] 
// AddPathList adds access for the specified environment variables to the existing state of the permission.
// SetPathList Sets the specified access to the specified environment variables to the existing state
// of the permission.
// GetPathList gets all environment variables with the specified EnvironmentPermissionAccess.
private:
bool SetGetPathListDemo() {
   try {
      Console::WriteLine(S"********************************************************\n");

      EnvironmentPermission* envPerm1;
      Console::WriteLine(S"Creating an EnvironmentPermission with AllAccess rights for 'TMP'");
      envPerm1 = new EnvironmentPermission(EnvironmentPermissionAccess::AllAccess, S"TMP");
      Console::WriteLine(S"Adding 'TEMP' to the write access list, and 'windir' to the read access list.");
      envPerm1->AddPathList(EnvironmentPermissionAccess::Write, S"TEMP");
      envPerm1->AddPathList(EnvironmentPermissionAccess::Read, S"windir");
      Console::WriteLine(S"Read access list before SetPathList = {0}", envPerm1->GetPathList(EnvironmentPermissionAccess::Read));
      Console::WriteLine(S"Setting read access to 'TMP'");
      envPerm1->SetPathList(EnvironmentPermissionAccess::Read, S"TMP");
      Console::WriteLine(S"Read access list after SetPathList = {0}", envPerm1->GetPathList(EnvironmentPermissionAccess::Read));
      Console::WriteLine(S"Write access list = {0}", envPerm1->GetPathList(EnvironmentPermissionAccess::Write));
      Console::WriteLine(S"Write access environment variables = {0}", envPerm1->GetPathList(EnvironmentPermissionAccess::AllAccess));
   } catch (ArgumentException* e) {
      // EnvironmentPermissionAccess::AllAccess cannot be used as a parameter for GetPathList.
      Console::WriteLine(S"An ArgumentException occurred as a result of using AllAccess."
         S"  This property cannot be used as a parameter in GetPathList, because it represents more than one type of environment variable :\n{0}", e);
   }

   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.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

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

Show:
© 2015 Microsoft