Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Components & Controls > Listviews / Treeviews

Listviews / Treeviews Anything related to listview and treeview components

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-01-2009, 7:48 AM
grmbl's Avatar
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
Post Populate treeview with registry

Hey,

Is there anyone here who could help me on my way to
create my own custom "regedit"?

First and probably only problem is iterating through the registry
starting from the root....

Anyone has experience with this topic?

Any help greatly appreciated!

grtz

__________________
"The world is coming to an end... SAVE YOUR BUFFERS !"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-01-2009, 10:25 AM
grmbl's Avatar
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

I allready found a solution and thought it would be a good idea to post it
here:

Code:
Dim root As TreeNode
        root = New TreeNode("This computer")
        root.ImageIndex = 5
        root.SelectedImageIndex = 5

        'HKEY_CLASSES_ROOT
        Dim rootnode As TreeNode
        rootnode = New TreeNode(Microsoft.Win32.Registry.ClassesRoot.Name.ToString)
        rootnode.ImageIndex = 4
        rootnode.SelectedImageIndex = 4
        Dim rootsubkeys() As String = Microsoft.Win32.Registry.ClassesRoot.GetSubKeyNames()
        For Each k As String In rootsubkeys
            Dim node As TreeNode
            node = New TreeNode(k)
            node.ImageIndex = 3
            node.SelectedImageIndex = 3
            Dim subkeys() As String = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(k).GetSubKeyNames()
            For Each subkeyskey As String In subkeys
                node.Nodes.Add(subkeyskey, subkeyskey, 0, 3)
            Next
            rootnode.Nodes.Add(node)
        Next
        root.Nodes.Add(rootnode)

tReg.Nodes.Add(root)

        tReg.Nodes(0).ExpandAll()
This can be used to list the whole registry.
The variables are "Microsoft.Win32.Registry.ClassesRoot" and the imageindices...

Hope this helps someone in the future!
__________________
"The world is coming to an end... SAVE YOUR BUFFERS !"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-02-2009, 7:11 AM
grmbl's Avatar
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

This is the more flexible code:

NOTE: this is not recursive!!! Not everything is shown!!!

(Uncomment imageindex/selectedimageindex if you have an imagelist set with
appropriate images and have a treeview with that imagelist set.)

Code:
Public Sub RegNode(ByVal tree As TreeView, ByVal reg As Microsoft.Win32.RegistryKey)

        Dim tn As TreeNode
        ' Add node with name of registrykey
        tn = New TreeNode(reg.Name.ToString)
        'tn.ImageIndex = 4
        'tn.SelectedImageIndex = 4

        'Get all the subkeynames and put them in an array
        Dim tns() As String = reg.GetSubKeyNames()

        'Loop through all subkeynames and their subkeys
        For Each k As String In tns
            Dim n As TreeNode
            n = New TreeNode(k)
            'n.ImageIndex = 3
            'n.SelectedImageIndex = 3
            Try
                Dim sk() As String = reg.OpenSubKey(k).GetSubKeyNames
                For Each sksk As String In sk
                    'n.Nodes.Add(sksk, sksk, 3, 3)
                    n.Nodes.Add(sksk, sksk)
                Next
            Catch ex As Exception
                'Failsafe for subkeys that are inaccessible
                'n.ImageIndex = 6
                'n.SelectedImageIndex = 6
            End Try
            tn.Nodes.Add(n)
        Next

        tree.Nodes.Add(tn)

End Sub
Usage:
Code:
RegNode(tReg, Microsoft.Win32.Registry.ClassesRoot)
Example:
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(tReg, Microsoft.Win32.Registry.ClassesRoot)
        RegNode(tReg, Microsoft.Win32.Registry.CurrentConfig)
        RegNode(tReg, Microsoft.Win32.Registry.CurrentUser)
        RegNode(tReg, Microsoft.Win32.Registry.LocalMachine)

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

End Sub
__________________
"The world is coming to an end... SAVE YOUR BUFFERS !"

Last edited by grmbl; 07-02-2009 at 9:30 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-03-2009, 8:33 AM
grmbl's Avatar
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 !"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 3:06 PM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.