EnvironmentPermission.SetPathList 方法
将对指定环境变量的指定访问权限设置为该权限的现有状态。
**命名空间:**System.Security.Permissions
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public Sub SetPathList ( _
flag As EnvironmentPermissionAccess, _
pathList As String _
)
用法
Dim instance As EnvironmentPermission
Dim flag As EnvironmentPermissionAccess
Dim pathList As String
instance.SetPathList(flag, pathList)
public void SetPathList (
EnvironmentPermissionAccess flag,
string pathList
)
public:
void SetPathList (
EnvironmentPermissionAccess flag,
String^ pathList
)
public void SetPathList (
EnvironmentPermissionAccess flag,
String pathList
)
public function SetPathList (
flag : EnvironmentPermissionAccess,
pathList : String
)
参数
- flag
EnvironmentPermissionAccess 值之一。
- pathList
环境变量的列表(用分号分隔)。
异常
异常类型 | 条件 |
---|---|
pathList 参数为 空引用(在 Visual Basic 中为 Nothing)。 |
|
flag 参数不是有效的 EnvironmentPermissionAccess 值。 |
备注
当前权限的前一状态被改写。
示例
下面的代码示例演示 SetPathList 方法的用法。此代码示例摘自一个为 EnvironmentPermission 类提供的更大的示例。
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
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;
}
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
EnvironmentPermission 类
EnvironmentPermission 成员
System.Security.Permissions 命名空间