How to get array of subkey names of any registry key in vb 6

 
The following example shows how to use the EnumKey method of the StdRegProv class to enumerate the subkeys in the Computer\ HKEY_CURRENT_USER \Software\Microsoft\ registry key.

Summery:

uint32 EnumKey( [in, optional] uint32 hDefKey = 2147483650, [in] string sSubKeyName, [out] string sNames[]);

where
hDefKey: A registry tree, also known as a hive (The default value is HKEY_LOCAL_MACHINE)

The following trees are defined in windows registry system:

HKEY_CLASSES_ROOT (2147483648 (0x80000000))
HKEY_CURRENT_USER (2147483649 (0x80000001))
HKEY_LOCAL_MACHINE (2147483650 (0x80000002))
HKEY_USERS (2147483651 (0x80000003))
HKEY_CURRENT_CONFIG (2147483653 (0x80000005))
HKEY_DYN_DATA (2147483654 (0x80000006))(for Windows 95 and Windows 98 computers only)

sSubKeyName: A path that contains the subkeys to be enumerated.

sNames: An array of subkey strings.

Example:

Private Sub GetArrayOfSubkeys()
    Const HKEY_CURRENT_USER = &H80000001
    Dim objReg As Object
    Dim regkeyPath As String
    Dim arrayOfSubKeys()
    Dim strAsk
    Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
 
    regkeyPath = "Software\Microsoft\"
    objReg.EnumKey HKEY_CURRENT_USER, regkeyPath, arrayOfSubKeys
End Sub

from the above arrayOfSubKeys will contain all the names of the subkeys under ‘Computer\ HKEY_CURRENT_USER \Software\Microsoft\’. If you want to get subkeys from HKEY_LOCAL_MACHINE hive, use the method as :

Private Sub GetArrayOfSubkeys()
    Const HKEY_LOCAL_MACHINE = &H80000002
    Dim objReg As Object
    Dim regkeyPath As String
    Dim arrayOfSubKeys()
    Dim strAsk
    Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
 
    regkeyPath = "Software\Microsoft\"
    objReg.EnumKey HKEY_LOCAL_MACHINE, regkeyPath, arrayOfSubKeys
End Sub