共用方式為


EnvironmentPermission.GetPathList(EnvironmentPermissionAccess) 方法

定義

使用指定的 EnvironmentPermissionAccess,取得所有環境變數。

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

參數

flag
EnvironmentPermissionAccess

其中一個 EnvironmentPermissionAccess 值,代表一種環境變數存取。

傳回

所選旗標的環境變數清單 (以分號分隔)。

例外狀況

flag 不是有效的 EnvironmentPermissionAccess 值。

-或-

flag 是代表多種環境變數存取的 AllAccess;如果不代表任何環境變數存取,則為 NoAccess

範例

下列程式代碼範例示範 如何使用 GetPathList 方法。 此程式代碼範例是提供給 類別之較大範例的 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

備註

使用這個方法來取得目前許可權的狀態。 若要取得 ReadWrite 存取狀態,需要對此方法進行兩次呼叫。

注意

參數 flag 僅限於的值,這些值 EnvironmentPermissionAccess代表單一類型的環境變數存取。 這些值為 ReadWrite。 可接受的值 flag 不包含 NoAccessAllAccess,這不代表單一類型的環境變數存取。

適用於