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\CurrentControlSet\Services\LanmanS­erver\Shares")

Dim RegKey As RegistryKey =
Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("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

Re: Recursive Registry Loop by Armin

Armin
Thu May 08 15:35:16 CDT 2008

"Derek Hart" <derekmhart@yahoo.com> schrieb
> 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


Re: Recursive Registry Loop by Derek

Derek
Thu May 08 16:42:11 CDT 2008

Been going in circles. If anybody has a code example, much appreciated!


"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:ejZsftUsIHA.4848@TK2MSFTNGP05.phx.gbl...
> "Derek Hart" <derekmhart@yahoo.com> schrieb
>> 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



Re: Recursive Registry Loop by Armin

Armin
Thu May 08 16:52:31 CDT 2008

"Derek Hart" <derekmhart@yahoo.com> schrieb
> 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