View Single Post
  #4 (permalink)  
Old 07-03-2009, 8:33 AM
grmbl's Avatar
grmbl grmbl is offline
VB.NET Forum Enthusiast
.NET Framework: .NET 3.0 (VS 2005/2008)
 
Join Date: Jun 2009
Location: Belgium
Age: 27
Posts: 32
Reputation: 12
grmbl is on a distinguished programming path ahead
Default

People, I need some help with this!!!
I tried recursively populating my treeview with the registry structure
but I'm stuck....

This is what I have so far:
Code:
Private Sub fRegistry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' Add node with computername
        'Dim root As TreeNode
        'root = New TreeNode(My.Computer.Name)
        'root.ImageIndex = 5
        'root.SelectedImageIndex = 5

        'tReg.Nodes.Add(root)

        'RegNode(Microsoft.Win32.Registry.ClassesRoot, tReg)
        'RegNode(Microsoft.Win32.Registry.CurrentConfig, tReg)
        'RegNode(Microsoft.Win32.Registry.CurrentUser, tReg)
        'RegNode(Microsoft.Win32.Registry.LocalMachine, tReg)
        'RegNode(Microsoft.Win32.Registry.Users, tReg)

        '' Expand computername node
        'tReg.Nodes(0).Expand()

        For Each key As Microsoft.Win32.RegistryKey In New Microsoft.Win32.RegistryKey() { _
                Microsoft.Win32.Registry.ClassesRoot, _
                Microsoft.Win32.Registry.CurrentConfig, _
                Microsoft.Win32.Registry.CurrentUser, _
                Microsoft.Win32.Registry.LocalMachine, _
                Microsoft.Win32.Registry.Users _
                }
            Dim rn As TreeNode
            rn = New TreeNode
            rn = TreeReg(key)
            rn.ImageIndex = 4
            rn.SelectedImageIndex = 4
            rn.Text = key.Name
            tReg.Nodes.Add(rn)
        Next

    End Sub

    Public Function TreeReg(ByVal key As Microsoft.Win32.RegistryKey) As TreeNode

        If key Is Nothing Then
            Return Nothing
        End If

        Dim tn As TreeNode
        tn = New TreeNode

        ' Valuenames under key
        For Each vn As String In key.GetValueNames()
            Dim valn As TreeNode
            valn = New TreeNode
            valn.Text = vn

            Dim value As Object = key.GetValue(vn)
            tn.Nodes.Add(valn)
        Next

        'Subkeynames under key/subkey
        For Each skn As String In key.GetSubKeyNames()
            Dim subn As TreeNode
            subn = New TreeNode
            subn.ImageIndex = 3
            subn.SelectedImageIndex = 3
            subn.Text = skn

            tn.Nodes.Add(subn)

            Try
                TreeReg(key.OpenSubKey(skn))
            Catch ex As Security.SecurityException
                ' can't search this one, just skip it
            End Try

        Next

        Return tn

    End Function
The problem lies with
Code:
TreeReg(key.OpenSubKey(skn))
Can anybody help to finally create something working and so it can be
shared. (because I haven't found anything on the web like this...)

Cheers,

grmbl!
__________________
"The world is coming to an end... SAVE YOUR BUFFERS !"
Reply With Quote