EnvironmentPermission.GetPathList(EnvironmentPermissionAccess) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
使用指定的 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
參數
其中一個 EnvironmentPermissionAccess 值,代表一種環境變數存取。
傳回
所選旗標的環境變數清單 (以分號分隔)。
例外狀況
flag
不是有效的 EnvironmentPermissionAccess 值。
-或-
範例
下列程式代碼範例示範 如何使用 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
備註
使用這個方法來取得目前許可權的狀態。 若要取得 Read
和 Write
存取狀態,需要對此方法進行兩次呼叫。
注意
參數 flag
僅限於的值,這些值 EnvironmentPermissionAccess代表單一類型的環境變數存取。 這些值為 Read 與 Write。 可接受的值 flag
不包含 NoAccess 和 AllAccess,這不代表單一類型的環境變數存取。