次の方法で共有


EnvironmentPermission.SetPathList メソッド

特定の環境変数に対して指定されているアクセス権をアクセス許可の既存の状態に設定します。

Public Sub SetPathList( _
   ByVal flag As EnvironmentPermissionAccess, _   ByVal pathList As String _)
[C#]
public void SetPathList(EnvironmentPermissionAccessflag,stringpathList);
[C++]
public: void SetPathList(EnvironmentPermissionAccessflag,String* pathList);
[JScript]
public function SetPathList(
   flag : EnvironmentPermissionAccess,pathList : String);

パラメータ

例外

例外の種類 条件
ArgumentNullException pathList パラメータが null 参照 (Visual Basic では Nothing) です。
ArgumentException flag パラメータが、 EnvironmentPermissionAccess の有効値ではありません。

解説

現在のアクセス許可の以前の状態は上書きされます。

使用例

 
' AddPathList adds access for the specified environment variables to the existing state of the permission.
' SetPathList Sets the specified access to the specified environment variables to the existing state 
' of the permission.
' GetPathList gets all environment variables with the specified EnvironmentPermissionAccess.
Private Function SetGetPathListDemo() As Boolean
    Try
        Console.WriteLine("********************************************************" & ControlChars.Lf)

        Dim envPerm1 As EnvironmentPermission
        Console.WriteLine("Creating an EnvironmentPermission with AllAccess rights for 'TMP'")
        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 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 : " & ControlChars.Lf & e.ToString()))
    End Try

    Return True
End Function 'SetGetPathListDemo


[C#] 
// AddPathList adds access for the specified environment variables to the existing state of the permission.
// SetPathList Sets the specified access to the specified environment variables to the existing state 
// of the permission.
// GetPathList gets all environment variables with the specified EnvironmentPermissionAccess.
private bool SetGetPathListDemo()
{
    try
    {
        Console.WriteLine("********************************************************\n");

        EnvironmentPermission envPerm1;
        Console.WriteLine("Creating an EnvironmentPermission with AllAccess rights for 'TMP'");
        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;        
}

[C++] 
// AddPathList adds access for the specified environment variables to the existing state of the permission.
// SetPathList Sets the specified access to the specified environment variables to the existing state
// of the permission.
// GetPathList gets all environment variables with the specified EnvironmentPermissionAccess.
private:
bool SetGetPathListDemo() {
   try {
      Console::WriteLine(S"********************************************************\n");

      EnvironmentPermission* envPerm1;
      Console::WriteLine(S"Creating an EnvironmentPermission with AllAccess rights for 'TMP'");
      envPerm1 = new EnvironmentPermission(EnvironmentPermissionAccess::AllAccess, S"TMP");
      Console::WriteLine(S"Adding 'TEMP' to the write access list, and 'windir' to the read access list.");
      envPerm1->AddPathList(EnvironmentPermissionAccess::Write, S"TEMP");
      envPerm1->AddPathList(EnvironmentPermissionAccess::Read, S"windir");
      Console::WriteLine(S"Read access list before SetPathList = {0}", envPerm1->GetPathList(EnvironmentPermissionAccess::Read));
      Console::WriteLine(S"Setting read access to 'TMP'");
      envPerm1->SetPathList(EnvironmentPermissionAccess::Read, S"TMP");
      Console::WriteLine(S"Read access list after SetPathList = {0}", envPerm1->GetPathList(EnvironmentPermissionAccess::Read));
      Console::WriteLine(S"Write access list = {0}", envPerm1->GetPathList(EnvironmentPermissionAccess::Write));
      Console::WriteLine(S"Write access environment variables = {0}", envPerm1->GetPathList(EnvironmentPermissionAccess::AllAccess));
   } catch (ArgumentException* e) {
      // EnvironmentPermissionAccess::AllAccess cannot be used as a parameter for GetPathList.
      Console::WriteLine(S"An ArgumentException occurred as a result of using AllAccess."
         S"  This property cannot be used as a parameter in GetPathList, because it represents more than one type of environment variable :\n{0}", e);
   }

   return true;
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

EnvironmentPermission クラス | EnvironmentPermission メンバ | System.Security.Permissions 名前空間