
Help needed with Registry sub-keys
I implemented RegEnumKeyEx for this purpose as follows.
Iteratively call getkeyname, incrementing the value of dwIndex until the
return is Null.
'*************** Code Start *******************
Private Declare Function RegOpenKeyEx Lib "advapi32" Alias _
"RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal dwReserved As Long, ByVal samDesired As Long, phkResult _
As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias
"RegEnumKeyExA" _
(ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, _
lpcbName As Long, lpReserved As Long, ByVal lpClass As String, _
lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
Function GetKeyName(hInKey As Long, ByVal subkey$, dwIndex As Long)
Dim hKey As Long
Dim lpName As String
Dim lpcbName As Long
Dim lpReserved As Long
Dim lpClass As String
Dim lpcbClass As Long
Dim lpftLastWriteTime As FILETIME
Dim lngRet As Long
Dim hSubKey As Long
'Dim RetVal$, , dwType As Long, SZ As Long
Const KEY_ALL_ACCESS As Long = &HF0063
Const ERROR_SUCCESS As Long = 0
Const REG_SZ As Long = 1
hKey = RegOpenKeyEx(hInKey, subkey$, 0, KEY_ALL_ACCESS, hSubKey)
If hKey <> ERROR_SUCCESS Then MsgBox "{*filter*}"
lpcbName = 256
lpName = String$(lpcbName, 0)
lpReserved = 0
lpClass = String$(1, 0)
lpcbClass = 0
lngRet = RegEnumKeyEx(hSubKey, dwIndex, lpName, lpcbName, lpReserved, _
lpClass, lpcbClass, lpftLastWriteTime)
GetKeyName = Left(lpName, lpcbName)
End Function
'*************** Code End *********************
I called the code above like this to fill a list box with the names of the
installed printers
'Code snippet
Dim lngX As Long
Dim strTemp As String
Dim strMsg As String
lngX = 0
Do
strTemp = GetKeyName(HKEY_CURRENT_CONFIG, _
"System\CurrentControlSet\Control\Print\Printers", lngX)
If Left(strTemp, 1) <> Chr$(0) Then
List1.AddItem strTemp
lngX = lngX + 1
End If
strTemp = Left(strTemp, 1)
Loop Until strTemp = Chr$(0)
Quote:
>Greetings
>Could someone please let me know how to accomplish the following:
>I need to retrieve UNKNOWN Sub-Keys from a Registry Key ie
>HKEY_CURRENT_USERS
> SOFTWARE
> <KEY> <SUB-KEY1> <DWORD Data etc>
> <SUB-KEY2>
> <SUB-KEY3>
>I do not need the DWORD data to the right of the Sub-Key.
>Any help is greatly appreciated.
>--
>Kind regards,
> Tony Jones, Gold Coast, Queensland, Australia
> Southern Cross Visual Basic Code and Links
> http://www.*-*-*.com/ ~scvb/index.html
> (If ' http://www.*-*-*.com/ ~scvb/...' fails, please use
>' http://www.*-*-*.com/ ')