Question [VS 2010] Creating Registry View

aljeff

Member
Joined
Feb 20, 2012
Messages
13
Programming Experience
Beginner
Hello, All.

Can someone help me to speed up the loading of application.
I'm creating a program like a Registry Editor but for viewing purposes only.
The program loads too slow because of my Try-catch for the security issues.

Here's the code.

VB.NET:
Imports Microsoft.Win32
Imports System.Security

Public Class Form1

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, RegistryKeyPermissionCheck.Default, Security.AccessControl.RegistryRights.ReadKey)
Dim vChildNode As New TreeNode(vSubKeyName)
'Dim vChildNode As New TreeNode(vSubKeyName.Name)
vChildNode = CreateNodes(vChildNode, vSubKey)
vParentNode.Nodes.Add(vChildNode)
' vParentNode.Nodes.Add(vSubKeyName)

Catch ex As 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


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Get registrykey for LocalMachine '

Dim vRegKeyLocalMachine As RegistryKey = Registry.LocalMachine
Dim vRegKeyClassesRoot As RegistryKey = Registry.ClassesRoot

' Create TreeNode and get its child nodes in CreateNodes method '

Dim vParentNode As New TreeNode(vRegKeyLocalMachine.Name)
Dim vParentNode2 As New TreeNode(vRegKeyClassesRoot.Name)

vParentNode = CreateNodes(vParentNode, vRegKeyLocalMachine)
vParentNode2 = CreateNodes(vParentNode2, vRegKeyClassesRoot)
' Show the nodes on treeview '

Dim root As TreeNode
root = New TreeNode(My.Computer.Name)

TreeView1.Nodes.Add(root)
TreeView1.Nodes.Add(vParentNode2)
TreeView1.Nodes.Add(vParentNode)

End Sub
End Class
 
Your code is difficult to read because of a lack of formatting. I see recursion there. Does that mean that you're loading the entire Registry up front? If so then that is going to be slow regardless of exceptions. You would want to go one, maybe two, levels deep at the most. Only when a user expands a particular node would you want to then go another level deep for that node specifically. That way there is always data available for the user to see at the next level but you keep the amount of data loaded to a minimum, thus speeding up the initial load.
 
Sadly yes. But I will recode the recursion.

Can you give me a sample of code of what you said if it is okay?

Or if you can help me to recode this one.
 
Back
Top