EnvironmentPermission.SetPathList(EnvironmentPermissionAccess, String) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Définit l’accès spécifié aux variables d’environnement spécifiées sur l’état existant de l’autorisation.
public:
void SetPathList(System::Security::Permissions::EnvironmentPermissionAccess flag, System::String ^ pathList);
public void SetPathList (System.Security.Permissions.EnvironmentPermissionAccess flag, string pathList);
member this.SetPathList : System.Security.Permissions.EnvironmentPermissionAccess * string -> unit
Public Sub SetPathList (flag As EnvironmentPermissionAccess, pathList As String)
Paramètres
Une des valeurs de l'objet EnvironmentPermissionAccess.
- pathList
- String
Liste des variables d’environnement (séparées par des points-virgules).
Exceptions
Le paramètre pathList
a la valeur null
.
Le paramètre flag
n’est pas une valeur valide de EnvironmentPermissionAccess.
Exemples
L’exemple de code suivant montre l’utilisation de la SetPathList méthode. Cet exemple de code fait partie d’un exemple plus grand fourni pour la EnvironmentPermission classe.
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
Remarques
L’état précédent de l’autorisation actuelle est remplacé.