次の方法で共有


RegistryPermission.AddPathList メソッド

指定したレジストリ変数へのアクセスをアクセス許可の既存の状態に追加します。

Public Sub AddPathList( _
   ByVal access As RegistryPermissionAccess, _   ByVal pathList As String _)
[C#]
public void AddPathList(RegistryPermissionAccessaccess,stringpathList);
[C++]
public: void AddPathList(RegistryPermissionAccessaccess,String* pathList);
[JScript]
public function AddPathList(
   access : RegistryPermissionAccess,pathList : String);

パラメータ

  • access
    RegistryPermissionAccess 値の 1 つ。
  • pathList
    レジストリ変数の (セミコロン区切りの) リスト。

例外

例外の種類 条件
ArgumentException access パラメータが、 RegistryPermissionAccess の有効値ではありません。

または

pathList パラメータが、有効な文字列ではありません。

解説

このメソッドを使用して現在のアクセス許可オブジェクトの状態に追加することによって、レジストリ変数へのアクセスを変更します。

使用例

 
' AddPathList adds access for the specified registry variables to the existing state of the permission.
' SetPathList sets new access for the specified registry variable names to the existing state of the permission.
' GetPathList gets paths for all registry variables with the specified RegistryPermissionAccess.
Private Function SetGetPathListDemo() As Boolean
    Try
        Console.WriteLine("********************************************************" & ControlChars.Lf)

        Dim regPerm1 As RegistryPermission
        Console.WriteLine("Creating RegistryPermission with AllAccess rights for 'HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0'")
        regPerm1 = New RegistryPermission(RegistryPermissionAccess.AllAccess, "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0")
        Console.WriteLine("Adding 'HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION' to the write access list, " & "and " & ControlChars.Lf & " 'HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\FloatingPointProcessor\0' " & "to the read access list.")
        regPerm1.AddPathList(RegistryPermissionAccess.Write, "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION")
        regPerm1.AddPathList(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\FloatingPointProcessor\0")
        Console.WriteLine("Read access list before SetPathList = " & regPerm1.GetPathList(RegistryPermissionAccess.Read))
        Console.WriteLine("Setting read access rights to " & ControlChars.Lf _
            & "'HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0'")
        regPerm1.SetPathList(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0")
        Console.WriteLine("Read access list after SetPathList = " _
            & ControlChars.Lf & regPerm1.GetPathList(RegistryPermissionAccess.Read))
        Console.WriteLine("Write access = " & ControlChars.Lf & regPerm1.GetPathList(RegistryPermissionAccess.Write))
        Console.WriteLine("Write access Registry variables = " & ControlChars.Lf & regPerm1.GetPathList(RegistryPermissionAccess.AllAccess))
    Catch e As ArgumentException
        ' RegistryPermissionAccess.AllAccess can not be used as a parameter for GetPathList.
        Console.WriteLine("An ArgumentException occured as a result of using AllAccess.  " _
            & "AllAccess cannot be used as a parameter in GetPathList because it represents more than one " _
            & "type of registry variable access : " & ControlChars.Lf & e.ToString())
    End Try

    Return True
End Function 'SetGetPathListDemo


[C#] 
// AddPathList adds access for the specified registry variables to the existing state of the permission.
// SetPathList sets new access for the specified registry variable names to the existing state of the permission.
// GetPathList gets paths for all registry variables with the specified RegistryPermissionAccess.
private bool SetGetPathListDemo()
{
    try
    {
        Console.WriteLine("********************************************************\n");

        RegistryPermission regPerm1;
        Console.WriteLine("Creating RegistryPermission with AllAccess rights for 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0'");
        regPerm1 = new RegistryPermission(RegistryPermissionAccess.AllAccess, "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
        Console.WriteLine("Adding 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION' to the write access list, " 
            + "and \n 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor\\0' " 
            + "to the read access list.");
        regPerm1.AddPathList(RegistryPermissionAccess.Write, "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION");
        regPerm1.AddPathList(RegistryPermissionAccess.Read, 
            "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor\\0");
        Console.WriteLine("Read access list before SetPathList = " + 
            regPerm1.GetPathList(RegistryPermissionAccess.Read));
        Console.WriteLine("Setting read access rights to \n'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0'");
        regPerm1.SetPathList(RegistryPermissionAccess.Read, 
            "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
        Console.WriteLine("Read access list after SetPathList = \n" + 
            regPerm1.GetPathList(RegistryPermissionAccess.Read));
        Console.WriteLine("Write access = \n" + 
            regPerm1.GetPathList(RegistryPermissionAccess.Write));
        Console.WriteLine("Write access Registry variables = \n" + 
            regPerm1.GetPathList(RegistryPermissionAccess.AllAccess));
    }
    catch (ArgumentException e)
    {
        // RegistryPermissionAccess.AllAccess can not be used as a parameter for GetPathList.
        Console.WriteLine("An ArgumentException occured as a result of using AllAccess.  " 
            + "AllAccess cannot be used as a parameter in GetPathList because it represents more than one " 
            + "type of registry variable access : \n" + e);
    }

    return true;        
}

[C++] 
// AddPathList adds access for the specified registry variables to the existing state of the permission.
// SetPathList sets new access for the specified registry variable names to the existing state of the permission.
// GetPathList gets paths for all registry variables with the specified RegistryPermissionAccess.
bool SetGetPathListDemo()
{
    try
    {
        Console::WriteLine(S"********************************************************\n");

        RegistryPermission* regPerm1;
        Console::WriteLine(S"Creating RegistryPermission with AllAccess rights for 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0'");
        regPerm1 = new RegistryPermission(RegistryPermissionAccess::AllAccess, S"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
        Console::WriteLine(S"Adding 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION' to the write access list, and \n 'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor\\0' to the read access list.");
        regPerm1->AddPathList(RegistryPermissionAccess::Write, S"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION");
        regPerm1->AddPathList(RegistryPermissionAccess::Read, 
            S"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor\\0");
        Console::WriteLine(S"Read access list before SetPathList = {0}", regPerm1->GetPathList(RegistryPermissionAccess::Read));
        Console::WriteLine(S"Setting read access rights to \n'HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0'");
        regPerm1->SetPathList(RegistryPermissionAccess::Read, 
            S"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
        Console::WriteLine(S"Read access list after SetPathList = \n{0}", regPerm1->GetPathList(RegistryPermissionAccess::Read));
        Console::WriteLine(S"Write access = \n{0}", regPerm1->GetPathList(RegistryPermissionAccess::Write));
        Console::WriteLine(S"Write access Registry variables = \n{0}", regPerm1->GetPathList(RegistryPermissionAccess::AllAccess));
    }
    catch (ArgumentException* e)
    {
        // RegistryPermissionAccess.AllAccess can not be used as a parameter for GetPathList.
        Console::WriteLine(S"An ArgumentException occured as a result of using AllAccess.  AllAccess cannot be used as a parameter in GetPathList because it represents more than one type of registry variable access : \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 ファミリ

参照

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