Compartir a través de


EnvironmentPermission.GetPathList(EnvironmentPermissionAccess) Método

Definición

Obtiene todas las variables de entorno con el elemento EnvironmentPermissionAccess especificado.

public:
 System::String ^ GetPathList(System::Security::Permissions::EnvironmentPermissionAccess flag);
public string GetPathList (System.Security.Permissions.EnvironmentPermissionAccess flag);
member this.GetPathList : System.Security.Permissions.EnvironmentPermissionAccess -> string
Public Function GetPathList (flag As EnvironmentPermissionAccess) As String

Parámetros

flag
EnvironmentPermissionAccess

Uno de los valores de EnvironmentPermissionAccess que representa un tipo único de acceso a variables de entorno.

Devoluciones

Una lista de variables de entorno (separadas por punto y coma) para la marca seleccionada.

Excepciones

flag no es un valor válido de EnvironmentPermissionAccess.

o bien

flag es AllAccess, que representa más de un tipo de acceso a variables de entorno; o NoAccess, que no representa ningún tipo de acceso a variable de entorno.

Ejemplos

En el ejemplo de código siguiente se muestra el uso del GetPathList método . Este ejemplo de código es parte de un ejemplo más grande proporcionado para la clase EnvironmentPermission.

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;
}
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

Comentarios

Use este método para obtener el estado del permiso actual. Para obtener los estados de acceso Read y Write , se requieren dos llamadas a este método.

Nota

El flag parámetro se limita a los valores de EnvironmentPermissionAccess, que representan tipos únicos de acceso a variables de entorno. Esos valores son Read y Write. Los valores aceptables para flag no incluir NoAccess y AllAccess, que no representan tipos únicos de acceso a variables de entorno.

Se aplica a