How do I enumerate or get all the values for a registry key name

specialfreckles
specialfreckles used Ask the Experts™
on
When my program starts up I would like it to list all the serial ports available on its computer

This key name
HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM

On my computer shows

Name                                  Type                   Data
(Default)                          REG_SIZE              (value not set)
\Device\536ep                 REG_SIZE              COM3
\Device\Serial0                REG_SIZE              COM1
\Device\Serial1                REG_SIZE              COM2

How can I find out how many entries there are for a key name and present each entry?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006
Commented:
you could try this

title :Enumerate Registry Subkeys, Entries and Values
source : http://www.freevbcode.com/ShowCode.Asp?ID=1156

----------
More information: A demo on enumerating registry subkeys, entries and values.
----------

hope this helps a bit

I suggest you to use this code:

http://www.vbaccelerator.com/home/VB/Code/Libraries/Registry_and_Ini_Files/Complete_Registry_Control/article.asp

it provides a nice class that is useful in any registry-related application. Moreover, this method:

EnumerateSections

lets you enumerate all the keys of a given registry section.
Hope this helps
M

Author

Commented:
marconovaro - Thanks for the tip- Worked out great
bruintje- I apprecite the input but it was a little too awkward.


Public RegFunc As New RegistryClass
Private CommPorts As New Collection


Private Sub GetCommports()
    Dim sKeys() As String, iKeyCount As Long, i As Integer
   
    Do While CommPorts.Count: CommPorts.Remove 1: Loop
    With RegFunc
        .ClassKey = HKEY_LOCAL_MACHINE
        .SectionKey = "HARDWARE\DEVICEMAP\SERIALCOMM"
        .EnumerateValues sKeys(), iKeyCount
        For i = 1 To iKeyCount
            .ValueKey = sKeys(i)
            .ValueType = REG_SZ
            CommPorts.Add .Value
        Next i
    End With
End Sub

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial