Registry TreeView

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
elation
Posts: 27
Last visit: Mon Sep 18, 2023 3:39 am
Has voted: 1 time

Registry TreeView

Post by elation »

Curious if anyone has an example or demo of treeview for browsing the registry.

Been using PowerShell Studio 2017 since January and cannot say enough good things about it. I've created some useful tools for my users and learned a bit along the way. Been perusing the forums and blogs since then with great success. That said, I've run into a small road-block with this one. I'd love to be able open a child window on my tech tool and browse to a select a reg key and/or value. I am currently using a combo box for HKLM/HKCU and then just a paste of the key/value.

Found some C# code that resembles what I'm looking for (I think) but no PowerShell GUI code.
Can't post a link since this is my first post. From the MSDN forum --> "treeview like RegEdit".

Any assistance or direction is greatly appreciated!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Registry TreeView

Post by jvierra »

The registry can be enumerated with Get-ChildItem just like a folder.

Get-ChildItem hklm: -recurse
User avatar
elation
Posts: 27
Last visit: Mon Sep 18, 2023 3:39 am
Has voted: 1 time

Re: Registry TreeView

Post by elation »

Thanks for the reply. I'll play around with it some more. It's a pretty complex control - was hoping someone may have already built a registry browse function with treeview. Therefore, I could learn by example. :)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Registry TreeView

Post by jvierra »

Here is an example of how to use the TreeView. Click a node to expand. Look at the code to see how the magic is accomplished.

The second file is a more complex example of how to handle complex objects in a TreeView.

Don't forget to read the articles in the Info Center.
Attachments
Demo-TreeviewFromPath.psf
(41.92 KiB) Downloaded 210 times
Demo-TreeviewFolders.psf
(23.55 KiB) Downloaded 193 times
User avatar
elation
Posts: 27
Last visit: Mon Sep 18, 2023 3:39 am
Has voted: 1 time

Re: Registry TreeView

Post by elation »

Much appreciated. I'll check them out. Been over the blogs a couple times but it's going to take some more reading for them to sink in.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Registry TreeView

Post by jvierra »

User avatar
elation
Posts: 27
Last visit: Mon Sep 18, 2023 3:39 am
Has voted: 1 time

Re: Registry TreeView

Post by elation »

Not much luck on this I'm afraid. Your examples, those from the Info Center, and others are helpful but I think this one might be out of my league for the time being. I've had really good success up until today. Maybe I can circle back in a month or two and see if anything jives then.

Short of manually adding a list to treeview, this is only way I've been able to successfully auto-populate a list. Couldn't do much past this, however.
  1. $keys = Get-ChildItem -Path Registry::HKEY_LOCAL_MACHINE\software
  2.     foreach ($key in $keys.name)
  3.     {
  4.         $treeview1.Nodes.Add($key)
  5.     }
User avatar
elation
Posts: 27
Last visit: Mon Sep 18, 2023 3:39 am
Has voted: 1 time

Re: Registry TreeView

Post by elation »

Couldn't sleep this morning and decided to take another stab. I think I'm well on the way to success now. I tried using a registry method (like was presented in the Explorer example) but quickly got confused. Instead, I went back to your suggestion of Get-ChildItem. The code below is doing basically what I would like. Now I just need to clean it up and plug it in where it's needed.

I forgot to add the event NodeMouseClick and when I tried this in a new form. That was frustrating to say the least.
  1. $form1_Load = {
  2.     $keys = Get-ChildItem -Path Registry::HKEY_LOCAL_MACHINE
  3.     foreach ($key in $keys.name)
  4.     {
  5.         $treeview1.Nodes.Add($key)
  6.     }
  7.    
  8. }
  9.  
  10. $treeview1_NodeMouseClick = [System.Windows.Forms.TreeNodeMouseClickEventHandler]{
  11.        
  12.     $node = $_.Node.Text
  13.     Try
  14.     {
  15.         if ($_.Node.Nodes.Count -eq 0)
  16.         {
  17.             $keys = Get-ChildItem -Path Registry::$node -ErrorAction SilentlyContinue
  18.             foreach ($key in $keys.name)
  19.             {
  20.                 $_.Node.Nodes.Add($key)
  21.             }
  22.         }
  23.     }
  24.    
  25.     Catch { }  
  26.    
  27. }
Thanks for the guidance!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Registry TreeView

Post by jvierra »

Here is a demo of how to easily use the registry with TreeView. It is rough but is man example of how to use the object capabilities along with the tree. This simplifies navigation.
Attachments
Demo-TreeviewRegistry.psf
(23.93 KiB) Downloaded 242 times
User avatar
elation
Posts: 27
Last visit: Mon Sep 18, 2023 3:39 am
Has voted: 1 time

Re: Registry TreeView

Post by elation »

So much cleaner than what I came up with (looks for the like button). The selectable value data on the right is great. I'm all set now! ;)
This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked