Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


EnvironmentPermission.GetPathList(EnvironmentPermissionAccess) Method

Definition

Gets all environment variables with the specified EnvironmentPermissionAccess.

public string GetPathList (System.Security.Permissions.EnvironmentPermissionAccess flag);

Parameters

flag
EnvironmentPermissionAccess

One of the EnvironmentPermissionAccess values that represents a single type of environment variable access.

Returns

A list of environment variables (semicolon-separated) for the selected flag.

Exceptions

flag is not a valid value of EnvironmentPermissionAccess.

-or-

flag is AllAccess, which represents more than one type of environment variable access, or NoAccess, which does not represent any type of environment variable access.

Examples

The following code example shows the use of the GetPathList method. This code example is part of a larger example provided for the EnvironmentPermission class.

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

Remarks

Use this method to get the state of the current permission. To get both Read and Write access states requires two calls to this method.

Megjegyzés

The flag parameter is limited to the values of EnvironmentPermissionAccess, which represent single types of environment variable access. Those values are Read and Write. The values acceptable to flag do not include NoAccess and AllAccess, which do not represent single types of environment variable access.

Applies to

Termék Verziók
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9