Click here to Skip to main content
Click here to Skip to main content

Get the registry keys recursively

By , 7 Oct 2005
 
  • <A href="GetRegistryKeys/getregistrykeys.zip"></A><A href="GetRegistryKeys/getregistrykeys.zip">Download source files - 47 Kb</A> 

Introduction

If you need to get the registry keys recursively you can use this function. This fills the textbox with the registry key and all inside.

The usual imports:

Imports Microsoft

Imports Microsoft.Win32

Imports Microsoft.Win32.Registry

The code is generated by a call:

</FONT></FONT>
' example: SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Dim key As String = txtKey.Text

TextBox1.Text = ""

TextBox1.Text = GetMyStrings(key)

This works for the HKEY_LOCAL_MACHINE main key. You can easily change to get the others.

First you open the main key with this:

</FONT></FONT>
Dim i As Integer

Dim k As String = key & vbCrLf

Dim k1 As String = ""

Dim R As Microsoft.Win32.RegistryKey = Registry.LocalMachine.OpenSubKey(key)

Dim a() As String = R.GetSubKeyNames

The R var opens the key and now we can get those subkeynames to an array. And now it is time to read all values inside this key with:

k += GetMyKeys(key)

This function reads those values and returns a string with it.

The secret for this to recursively works is in the GetMyStrings function. Let's see it:

</FONT></FONT></FONT></FONT>
For i = 0 To a.Length - 1

k1 = key & "\" & a(i)

k += k1 & vbCrLf

If Registry.LocalMachine.OpenSubKey(k1).SubKeyCount > 0 Then

' recursively step in this function to get all my new keys

' that are in this one. all variables are preserved as normally

' in recursive functions
k += GetMyStrings(k1)

End If

Next

Let's go key by key and check if there are another keys inside this one and if there are, just call this function recursively. The new parameter is the new key. And the function just goes and do the work.

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Adelino Araújo
Portugal Portugal
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 1 PinmvpDave Kreskowiak10 Nov '09 - 7:30 
GeneralSource code PinmemberVitaly7 Oct '05 - 22:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 7 Oct 2005
Article Copyright 2005 by Adelino Araújo
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid