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

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

This key name

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?
Watch Question

Do more with

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

title :Enumerate Registry Subkeys, Entries and Values
source :

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

hope this helps a bit

I suggest you to use this code:

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


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


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
        .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