Export (0) Print
Expand All

RegistryPermission.Copy Method

Creates and returns an identical copy of the current permission.

[Visual Basic]
Overrides Public Function Copy() As IPermission Implements _
   IPermission.Copy
[C#]
public override IPermission Copy();
[C++]
public: IPermission* Copy();
[JScript]
public override function Copy() : IPermission;

Return Value

A copy of the current permission.

Implements

IPermission.Copy

Remarks

A copy of a permission represents the same access to resources as the original permission.

Example

[Visual Basic] 
'Copy creates and returns an identical copy of the current permission.
Private Function CopyDemo() As Boolean

    Dim returnValue As Boolean = True
    Dim reg1 As String
    Dim regPerm1, regPerm2 As RegistryPermission
    Dim regGen1 As New regGenerator()
    Dim regGen2 As New regGenerator()

    regGen1.ResetIndex()
    While regGen1.CreateReg(regPerm1, reg1, RegistryPermissionAccess.Read)
        If reg1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        regGen2.ResetIndex()
        Try
            regPerm2 = CType(regPerm1.Copy(), RegistryPermission)
            If Not (regPerm2 Is Nothing) Then
                Console.WriteLine(("Result of copy = " & regPerm2.ToString() & ControlChars.Lf))
            Else
                Console.WriteLine("Result of copy is null. " & ControlChars.Lf)
            End If
        Catch e As Exception
            If (True.ToString()) Then
                If reg1 = "" Then
                    Console.WriteLine("The target RegistryPermission is empty; copy failed.")

                Else
                    Console.WriteLine(e.ToString())
                End If
            End If
            GoTo ContinueWhile1
        End Try
ContinueWhile1:
    End While
    Return returnValue
End Function 'CopyDemo


[C#] 
//Copy creates and returns an identical copy of the current permission.
private bool CopyDemo()
{

    bool returnValue = true;
    string reg1;
    RegistryPermission regPerm1,regPerm2;
    RegGenerator regGen1 = new RegGenerator();
    RegGenerator regGen2 = new RegGenerator();

    regGen1.ResetIndex();
    while(regGen1.CreateReg(out regPerm1, out reg1, RegistryPermissionAccess.Read)) 
    {
        if(reg1 == null ) continue;  
        regGen2.ResetIndex();
        try
        {            
            regPerm2 = (RegistryPermission)regPerm1.Copy();
            if (regPerm2 != null)
            {
                Console.WriteLine("Result of copy = " + regPerm2.ToString() + "\n");
            }
            else
            {
                Console.WriteLine("Result of copy is null. \n");
            }
        }
        catch(Exception e) 
        {
        {
            if (reg1 == "")
            {
                Console.WriteLine( "The target RegistryPermission is empty; copy failed.");

            }
            else
                Console.WriteLine( e);
        }
            continue;
        }
    }
    return returnValue;
}

[C++] 
//Copy creates and returns an identical copy of the current permission.
bool CopyDemo()
{

    bool returnValue = true;
    String* reg1;
    RegistryPermission* regPerm1;
    RegistryPermission* regPerm2;
    RegGenerator* regGen1 = new RegGenerator();
    RegGenerator* regGen2 = new RegGenerator();

    regGen1->ResetIndex();
    while(regGen1->CreateReg(&regPerm1, &reg1, RegistryPermissionAccess::Read)) 
    {
        if(reg1 == 0 ) continue;  
        regGen2->ResetIndex();
        try
        {            
            regPerm2 = dynamic_cast<RegistryPermission*>(regPerm1->Copy());
            if (regPerm2 != 0)
            {
                Console::WriteLine(S"Result of copy = {0}\n", regPerm2);
            }
            else
            {
                Console::WriteLine(S"Result of copy is null. \n");
            }
        }
        catch(Exception* e) 
        {
            {
                if (reg1->Equals(S""))
                {
                    Console::WriteLine( S"The target RegistryPermission is empty; copy failed.");

                }
                else
                    Console::WriteLine( e);
            }
            continue;
        }
    }
    return returnValue;
}

[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:
© 2014 Microsoft