次の方法で共有


RegistryPermission.GetPathList メソッド

指定した RegistryPermissionAccess を持つすべてのレジストリ変数のパスを取得します。

Public Function GetPathList( _
   ByVal access As RegistryPermissionAccess _) As String
[C#]
public string GetPathList(RegistryPermissionAccessaccess);
[C++]
public: String* GetPathList(RegistryPermissionAccessaccess);
[JScript]
public function GetPathList(
   access : RegistryPermissionAccess) : String;

パラメータ

戻り値

指定した RegistryPermissionAccess を示す、レジストリ変数の (セミコロン区切りの) リスト。

例外

例外の種類 条件
ArgumentException access が有効な RegistryPermissionAccess 値ではありません。

または

access が、複数の種類のレジストリ変数アクセス許可を表す AllAccess か、どの種類のレジストリ変数アクセス許可も表さない NoAccess です。

解説

このメソッドを使用して、現在のアクセス許可の状態を取得します。このメソッドは、アクセスの種類ごとに呼び出す必要があります。

メモ    access パラメータに指定できるのは、単一の種類のレジストリ変数アクセス許可を表す RegistryPermissionAccess の値だけです。これらの値は、 ReadWrite 、および Create です。 NoAccess および AllAccess は、単一の種類のレジストリ変数アクセス許可を表さないため、 access では使用できません。

使用例

 
' 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 名前空間