Test - code pasting in messages - Test

RGM

Member
Joined
Nov 6, 2012
Messages
6
Programming Experience
Beginner
code:

Imports Microsoft.Win32
 
Public Class FRM_BrowseRegistry
    'Create a Delegate
    Delegate Sub TV_RegistryAddNodeDelegate(ByVal NodeName As TreeNode)
 
    'Declare a class that contains a method with the same signature as the delegate
    Public Class ShowtreeNodeClass
 
        Sub ShowTreeNodeMethod(ByVal NodeName As TreeNode)
            FRM_BrowseRegistry.TV_Registry.Nodes.Add(NodeName)
        End Sub
 
    End Class
 
 
    Public Sub FRM_BrowseRegistry_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 
        BackgroundWorker1.RunWorkerAsync()
 
    End Sub
 
    Public Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
 
        'Get registrykey for HKEY_CLASSES_ROOT'  
        Dim vRegKeyClassesRoot As RegistryKey = Registry.ClassesRoot
        'Create TreeNode and get its child nodes in CreateNodes method '  
        Dim ClassesRootParentNode As New TreeNode(vRegKeyClassesRoot.Name)
        ClassesRootParentNode = CreateNodes(ClassesRootParentNode, vRegKeyClassesRoot)
        'Show the node on treeview, use invoke as the treeview is updated from a background thread 
        Dim MyShowTreeNodeClass As New ShowtreeNodeClass
        'Create an instance of the delegate
        Dim MyShowTreeDelegate As TV_RegistryAddNodeDelegate = AddressOf MyShowTreeNodeClass.ShowTreeNodeMethod
        MyShowTreeDelegate.Invoke(ClassesRootParentNode)
 
    End Sub
 
    Private Function CreateNodes(ByVal vParentNode As TreeNode, ByVal vRegKey As RegistryKey) As TreeNode
 
        For Each vSubKeyName As String In vRegKey.GetSubKeyNames()
            Try
                ' Open subkey and create a childnode with subkeys name on it '  
                ' Then create childnodes for childnode '   
                Dim vSubKey As RegistryKey = vRegKey.OpenSubKey(vSubKeyName, False, Security.AccessControl.RegistryRights.ReadKey)
                Dim vChildNode As New TreeNode(vSubKey.Name)
                vChildNode = CreateNodes(vChildNode, vSubKey)
                vParentNode.Nodes.Add(vChildNode)
            Catch ex As Security.SecurityException
                ' Lots of security exceptions will be thrown if user is not admin or doesnt have access for whole registry '   
            Catch ex As Exception
            End Try
        Next
        Return vParentNode
 
    End Function
 
End Class 'FRM_BrowseRegistry
 
Last edited:
Back
Top