473,395 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Recursive Registry Loop

I simply want to loop through a registry key, and have all subkeys and
values outputed to the console window. It needs to be recursive, so it keeps
going into each key one at a time, until it finishes. My code is not close.
Anybody have code that has done this?

Dim GroupID As Long = 39

'Dim RegKey As RegistryKey =
Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentCo ntrolSet\Services\LanmanS*erver\Shares")

Dim RegKey As RegistryKey =
Registry.CurrentUser.OpenSubKey("Software").OpenSu bKey("VB and VBA Program
Settings").OpenSubKey("iGen").OpenSubKey("Group"). OpenSubKey(GroupID).OpenSubKey("Printer
Settings")

Dim tempKey As RegistryKey

Do Until RegKey.SubKeyCount = 0

Console.WriteLine("There are {0} subkeys under " & RegKey.Name & ".",
RegKey.SubKeyCount.ToString())

Console.WriteLine(vbCrLf & "There are {0} values for " & "{1}.",
RegKey.ValueCount.ToString(), RegKey.Name)

For Each valueName As String In RegKey.GetValueNames()

Console.WriteLine("{0,-8}: {1}", valueName,
RegKey.GetValue(valueName.ToString))

Next

For Each subKeyName As String In RegKey.GetSubKeyNames()

tempKey = RegKey.OpenSubKey(subKeyName)

Console.WriteLine(vbCrLf & "There are {0} values for " & "{1}.",
tempKey.ValueCount.ToString(), tempKey.Name)

For Each valueName As String In tempKey.GetValueNames()

Console.WriteLine("{0,-8}: {1}", valueName,
tempKey.GetValue(valueName.ToString))

Next

Next

If Not tempKey Is Nothing Then RegKey = tempKey

Loop

Console.ReadLine()

End Sub
Jun 27 '08 #1
3 6566
"Derek Hart" <de********@yahoo.comschrieb
I simply want to loop through a registry key, and have all subkeys
and values outputed to the console window. It needs to be recursive,
so it keeps going into each key one at a time, until it finishes. My
code is not close. Anybody have code that has done this?
Write a Sub that expects a RegKey object, and
1. outputs all values
2. retrieves the sub key names
3. loops over the sub key names and opens each one, and calls the same
Sub again passing the new RegKey just created.

Just translate to VB. That's all.

Isn't your question the answer? :-)
Armin

Jun 27 '08 #2
Been going in circles. If anybody has a code example, much appreciated!
"Armin Zingler" <az*******@freenet.dewrote in message
news:ej**************@TK2MSFTNGP05.phx.gbl...
"Derek Hart" <de********@yahoo.comschrieb
>I simply want to loop through a registry key, and have all subkeys
and values outputed to the console window. It needs to be recursive,
so it keeps going into each key one at a time, until it finishes. My code
is not close. Anybody have code that has done this?

Write a Sub that expects a RegKey object, and
1. outputs all values
2. retrieves the sub key names
3. loops over the sub key names and opens each one, and calls the same Sub
again passing the new RegKey just created.

Just translate to VB. That's all.

Isn't your question the answer? :-)
Armin

Jun 27 '08 #3
"Derek Hart" <de********@yahoo.comschrieb
Been going in circles. If anybody has a code example, much
appreciated!
Untested:

Private Shared Sub OutputRegKey( _
ByVal RegKey As Microsoft.Win32.RegistryKey)

For Each ValueName In RegKey.GetValueNames
Debug.Print(RegKey.GetValue(ValueName).ToString)
Next

For Each KeyName In RegKey.GetSubKeyNames
Using Key = RegKey.OpenSubKey(KeyName, False)
OutputRegKey(Key)
End Using
Next

End Sub
Call:

OutputRegKey( _
Microsoft.Win32.Registry.LocalMachine.OpenSubKey( _
"SYSTEM\CurrentControlSet\Services\LanmanSÂ*erver\ Shares" _
) _
)

AZ

Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Xavier Decoret | last post by:
I am reading the lines of a file, executing appropriate command if a pattern is found. One of the pattern can be a input command whose effect should be to #include the file (possibly recursively) ...
19
by: Carlos Ribeiro | last post by:
Hello all, Here I am using some deeply nested, tree-like data structures. In some situations I need to traverse the tree; the old-style way to do it is to write a recursive method on the node...
10
by: Steve Goldman | last post by:
Hi, I am trying to come up with a way to develop all n-length permutations of a given list of values. The short function below seems to work, but I can't help thinking there's a better way. ...
7
by: aurora | last post by:
I love generator and I use it a lot. Lately I've been writing some recursive generator to traverse tree structures. After taking closer look I have some concern on its performance. Let's take...
2
by: LCD | last post by:
Here is what I want to do: Presently in my registry I have: (Default) = "C:\Program Files\myApp" and this value is scattered all over registry in several keys and subkeys. I wouldlike to...
3
by: jcrouse | last post by:
I am trying trying to loop through some label controls and setting some properties for the labels I'm looping through. Currently I am addressing the labels one at a time with IF...Then logic, like...
12
by: Li Pang | last post by:
Hi, I'd like to know how to remove registry keys which contain a value of 'appkeyA' or 'appkeyB' or 'appkeyC' ...? thanks in advance
6
by: JOSII | last post by:
Getting a string of boolean value into and out of the registry is no problem. Here's the problem: Although you can place an object into the registry and retreive it, I need to place an ArrayList...
4
by: maheswaran | last post by:
Hi all, I have problem in getting data from database using recursive function... I have the table called "master_info" project id | Child_of | Project_name...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.