Export (0) Print
Expand All

RegistryPermission.GetPathList Method

Gets paths for all registry variables with the specified RegistryPermissionAccess.

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

Parameters

access
One of the RegistryPermissionAccess values that represents a single type of registry variable access.

Return Value

A list of the registry variables (semicolon-separated) with the specified RegistryPermissionAccess.

Exceptions

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

-or-

access is AllAccess, which represents more than one type of registry variable access, or NoAccess, which does not represent any type of registry variable access.

Remarks

Use this method to get the state of the current permission. You must call this method separately for each type of access.

Note   The access parameter is limited to the values of RegistryPermissionAccess, which represent single types of registry variable access. Those values are Read, Write, and Create. The values acceptable to access do not include NoAccess and AllAccess, which do not represent single types of registry variable access.

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:
© 2015 Microsoft