Freigeben über


EnvironmentPermission.SetPathList-Methode

Setzt den angegebenen Zugriff für die angegebenen Umgebungsvariablen auf den derzeitigen Berechtigungsstatus.

Namespace: System.Security.Permissions
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Sub SetPathList ( _
    flag As EnvironmentPermissionAccess, _
    pathList As String _
)
'Usage
Dim instance As EnvironmentPermission
Dim flag As EnvironmentPermissionAccess
Dim pathList As String

instance.SetPathList(flag, pathList)
public void SetPathList (
    EnvironmentPermissionAccess flag,
    string pathList
)
public:
void SetPathList (
    EnvironmentPermissionAccess flag, 
    String^ pathList
)
public void SetPathList (
    EnvironmentPermissionAccess flag, 
    String pathList
)
public function SetPathList (
    flag : EnvironmentPermissionAccess, 
    pathList : String
)

Parameter

  • pathList
    Eine Liste von Umgebungsvariablen (durch Semikolon getrennt).

Ausnahmen

Ausnahmetyp Bedingung

ArgumentNullException

Der pathList-Parameter ist NULL (Nothing in Visual Basic).

ArgumentException

Der flag-Parameter ist kein gültiger Wert von EnvironmentPermissionAccess.

Hinweise

Der bisherige Zustand der aktuellen Berechtigung wird überschrieben.

Beispiel

Im folgenden Codebeispiel wird die Verwendung der SetPathList-Methode veranschaulicht. Dieses Codebeispiel ist Teil eines umfangreicheren Beispiels für die EnvironmentPermission-Klasse.

Private Function SetGetPathListDemo() As Boolean 
    Try
        Console.WriteLine("********************************************************" + vbLf)
        Console.WriteLine("Creating an EnvironmentPermission with AllAccess rights for 'TMP'")
        Dim envPerm1 As 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 : " + vbLf + e.Message)
    End Try
    
    Return True

End Function 'SetGetPathListDemo
private bool SetGetPathListDemo()
{
    try
    {
        Console.WriteLine("********************************************************\n");
        Console.WriteLine("Creating an EnvironmentPermission with AllAccess rights for 'TMP'");
        EnvironmentPermission 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;
}

Plattformen

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 unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

EnvironmentPermission-Klasse
EnvironmentPermission-Member
System.Security.Permissions-Namespace