While regGen2.CreateReg(regPerm2, reg2, RegistryPermissionAccess.Read)
If regPerm2 Is Nothing Then
GoTo ContinueWhile2
End If
Dim firstPermission As String = IIf(reg1 = "" Or reg1 Is _
Nothing, "null", reg1)
Dim secondPermission As String = IIf(reg2 = "" Or reg2 Is _
Nothing, "null", reg2)
Try
regIdPerm3 = CType(regPerm1.Intersect(regPerm2), _
RegistryPermission)
If Not (regIdPerm3 Is Nothing) AndAlso Not ( _
regIdPerm3.GetPathList(RegistryPermissionAccess.Read) Is _
Nothing) Then
Console.WriteLine(("The intersection of " & _
firstPermission & " and " & ControlChars.Lf & _
ControlChars.Tab & secondPermission & " = " & _
ControlChars.Lf & ControlChars.Tab & CType( _
regIdPerm3, RegistryPermission).GetPathList( _
RegistryPermissionAccess.Read).ToString()))
Else
Console.WriteLine(("The intersection of " & _
firstPermission & " and " & ControlChars.Lf & _
ControlChars.Tab & secondPermission & " is null. "))
End If
Catch e As Exception
Console.WriteLine(("An exception was thrown for" & _
"intersection : " & e.ToString()))
returnValue = False
End Try
ContinueWhile2:
End While
ContinueWhile1:
End While
Return returnValue
End Function 'IntersectDemo
'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
' ToXml creates an XML encoding of the permission and its current state;
' FromXml
' reconstructs a permission with the specified state from the XML encoding.
Private Function ToFromXmlDemo() 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 regPerm1 Is Nothing Then
GoTo ContinueWhile1
End If
Console.WriteLine( _
"********************************************************" & _
ControlChars.Lf)
regGen2.ResetIndex()
Try
regPerm2 = New RegistryPermission(PermissionState.None)
regPerm2.FromXml(regPerm1.ToXml())
Console.WriteLine(("Result of ToFromXml = " & regPerm2.ToString( _
) & ControlChars.Lf))
Catch e As Exception
Console.WriteLine(("ToFromXml failed :" & regPerm1.ToString() & _
e.ToString()))
GoTo ContinueWhile1
End Try
ContinueWhile1:
End While
Return returnValue
End Function 'ToFromXmlDemoFortsetzung folgt...
MfG
Visual Studio .Net Team Suite 2008 - Meine neue lieblings IDE
.png) |