• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

Reading registry

Once I've created several keys in the registry using SaveSettings, is there an easy way to enumerate all sections/keys?

For instance, if my hierarchy looks like

VB..Settings\MyAppName\MySection

and under MySection, I have

Folder1
Folder2
etc

and each FolderX has values of

Value1=100
Value2=200
Value3=300
etc

How can I easily loop through these acquiring the section/key names and values?


0
sirbounty
Asked:
sirbounty
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
Wayne Taylor (webtubbs)Commented:
Hi sirbounty,

You might be able to iterate over the sections with an "Index". If you already know the number of sections, you can use something like this....

    Dim i As Long
    Dim n As Long
    For i = 1 to 6 '\\with 6 being the number of sections
        For n = 1 to 8 '\\with 8 being the number of values
            If GetSetting("MyAppName", "Folder" & i, "Value" & n, "") <> "" Then
                'do something
                'Folder = "Folder" & i
                'ValueName = "Value" & i
                'Value = GetSetting("MyAppName", "Folder" & i, "Value" & n, "")
            End If
        Next
    Next

If set the upper limit of both i and n to something that is known to be higher than that that actually exists, the code will continue to iterate over them, but will do nothing as GetSetting(...) will return "" if any of it's parameters are not found.

Regards,

Wayne
0
 
Wayne Taylor (webtubbs)Commented:
Correction....
 
     ValueName = "Value" & n
0
 
sirbountyAuthor Commented:
Were these actually named Folder1, 2, etc, that might be feasible, but they're a bit more specific than that, unfortunately, with no counter.

I can retrieve everything I need using a command-line "reg query" loop.  I was hoping I could accomplish this without a shell though..
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
GrahamSkanRetiredCommented:
You couls also use GetAllSettings.

This is Microsoft's example

GetAllSettings Function Example
This example first uses the SaveSetting statement to make entries in the Windows registry for the application specified as appname, then uses the GetAllSettings function to display the settings. Note that application names and section names can't be retrieved with GetAllSettings. Finally, the DeleteSetting statement removes the application's entries.

' Variant to hold 2-dimensional array returned by GetAllSettings
' Integer to hold counter.
Dim MySettings As Variant, intSettings As Integer
' Place some settings in the registry.
SaveSetting appname := "MyApp", section := "Startup", _
key := "Top", setting := 75
SaveSetting "MyApp","Startup", "Left", 50
' Retrieve the settings.
MySettings = GetAllSettings(appname := "MyApp", section := "Startup")
   For intSettings = LBound(MySettings, 1) To UBound(MySettings, 1)
      Debug.Print MySettings(intSettings, 0), MySettings(intSettings, 1)
   Next intSettings
DeleteSetting "MyApp", "Startup"


0
 
ShauliCommented:
Dim MySettings As Variant, cLoop As Integer
MySettings = GetAllSettings("MyApp", "Startup")
   For cLoop = LBound(MySettings, 1) To UBound(MySettings, 1)
      Debug.Print MySettings(cLoop, 0), MySettings(cLoop, 1)
   Next cLoop

'GetAllSettings read all the keys in a given location and creates an array, so loop among the array elements to read the keys.

S


0
 
ShauliCommented:
Opps, GrahamSkan was faster...

S
0
 
GrahamSkanRetiredCommented:
Only by a minute - I didn't edit the example.
0
 
ShauliCommented:
You should, don't you? :)

S
0
 
sirbountyAuthor Commented:
That gets me much closer at least.  I suppose that's about as close as I'll get going this route.
Thanx for the help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now