EnvironmentPermission.AddPathList(EnvironmentPermissionAccess, String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将指定的环境变量的访问权限添加到现有的权限状态中。
public:
void AddPathList(System::Security::Permissions::EnvironmentPermissionAccess flag, System::String ^ pathList);
public void AddPathList (System.Security.Permissions.EnvironmentPermissionAccess flag, string pathList);
member this.AddPathList : System.Security.Permissions.EnvironmentPermissionAccess * string -> unit
Public Sub AddPathList (flag As EnvironmentPermissionAccess, pathList As String)
参数
- pathList
- String
环境变量列表(用分号分隔)。
例外
pathList
参数为 null
。
flag
参数不是 EnvironmentPermissionAccess 的有效值。
示例
下面的代码示例演示了该方法的使用 AddPathList 。
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
注解
使用此方法通过添加到当前权限的状态来修改环境变量访问。