This documentation is archived and is not being maintained.

RegistryPermission.SetPathList Method

Sets new access for the specified registry variable names to the existing state of the permission.

[Visual Basic]
Public Sub SetPathList( _
   ByVal access As RegistryPermissionAccess, _
   ByVal pathList As String _
)
[C#]
public void SetPathList(
 RegistryPermissionAccess access,
 string pathList
);
[C++]
public: void SetPathList(
 RegistryPermissionAccess access,
 String* pathList
);
[JScript]
public function SetPathList(
   access : RegistryPermissionAccess,
 pathList : String
);

Parameters

access
One of the RegistryPermissionAccess values.
pathList
A list of registry variables (semicolon-separated).

Exceptions

Exception Type Condition
ArgumentException The access parameter is not a valid value of RegistryPermissionAccess.

-or-

The pathList parameter is not a valid string.

Remarks

The previous state of the current permission is overwritten.

Example

[Visual Basic] 
' 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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

RegistryPermission Class | RegistryPermission Members | System.Security.Permissions Namespace

Show: