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.
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