Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello I am aware that the registry class exists for vb.net but am a bit confused as to how its possible to enumerate all levels to a label or textbox in succession one key after another like a virus scanner iterating over a filesystem.

I have been trying to use this bit of code that I have found can anyone shed a bit of knowledge on this?

VB
Public Function GetAllChildSubKeys(ByVal MainKey As RegistryKey, ByVal sKey As String) As ArrayList
       Dim rkKey As RegistryKey    'RegistryKey to work with
       Dim sSubKeys() As String    'string array to hold the subkeys
       Dim arySubKeys As New ArrayList 'arraylist to return the subkeys in an array
       Try
           'open the given subkey
           rkKey = MainKey.OpenSubKey(sKey)
           'check to see if the subkey exists
           If Not sKey Is Nothing Then 'subkey exists
               'get all the child subkeys
               sSubKeys = rkKey.GetSubKeyNames
               'loop through all the child subkeys
               For Each s As String In sSubKeys
                   'add them to the arraylist
                   arySubKeys.Add(s)
               Next
           Else    'subkey doesnt exist
               'throw an exception
               Throw New Exception("The SubKey provided doesn't exist. Please check your entry and try again.")
           End If
       Catch ex As Exception
           MessageBox.Show(ex.Message, "Error: Retrieving SubKeys", MessageBoxButtons.OK, MessageBoxIcon.Error)
       End Try
       'return the subkeys arraylist
       Return arySubKeys
   End Function



Thank you in advance!!
Posted
Comments
Sergey Alexandrovich Kryukov 24-Oct-12 23:44pm    
And what's the question? What's is the problem?
--SA
Dale 2012 24-Oct-12 23:54pm    
the question to my problem is simply to show the recursion of the registry to a label like a scanner normally would. I would like to enumerate all levels of the registry and have a label show it. how might I accomplish this?
Sergey Alexandrovich Kryukov 26-Oct-12 0:32am    
What's the problem with your current code?

Also, there is no need to use Win32 API (I refer to your next question I removed as re-post). Why did you ask? you already started to use Microsoft.Win32.Registry from FCL...
--SA
Dale 2012 26-Oct-12 21:57pm    
I am only looking for some example with some insight into things as i am trying to learn but it is confusing to me and this code is also a bit confusing. what is FCL?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900