Well, the problem is that I want to do it by means of VBA.code. Any
suggestions?
/BosseH
> You don't need to muck around with API calls for this. Run Regedit. Right
> click the root directory under which you want the sub-entries and click
[quoted text clipped - 7 lines]
>>
>> /BosseH
Option Explicit
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias
"RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal
ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey 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
Const HKCR = &H80000000
Const HKCU = &H80000001
Const HKLM = &H80000002
Const HKKU = &H80000003
Const HKPD = &H80000004
Const HKCC = &H80000005
Const HKDD = &H80000006
Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Sub XXX()
Dim keyname As String ' Receives keyname for each subkey
Dim keylen As Long ' Length of keyname
Dim classname As String ' Receives class name for each subkey
Dim classlen As Long ' Length of classname
Dim lastwrite As FILETIME ' Receives last-write-to time
Dim handle As Long ' handle to the opened key
Dim index As Long ' Index counter
Dim rval As Long ' Return value
Dim oupval As String
oupval = "Sub-Keys are " & Chr(13)
rval = RegOpenKeyEx(HKCU, "", 0, KEY_ENUMERATE_SUB_KEYS, handle)
If rval <> 0 Then
MsgBox "Registry key could not be opened."
Exit Sub
End If
Do While rval = 0 ' Continue if success
keylen = 255
keyname = Space(keylen)
classlen = 255
classname = Space(classlen)
rval = RegEnumKeyEx(handle, index, keyname, keylen, ByVal 0, classname,
classlen, lastwrite)
If rval = 0 Then
keyname = Left$(keyname, keylen)
Debug.Print "HKCU\" & keyname
End If
Loop ' End the loop
rval = RegCloseKey(handle)
End Sub
> Well, the problem is that I want to do it by means of VBA.code. Any
> suggestions?
[quoted text clipped - 12 lines]
>>>
>>> /BosseH
Bo Hansson - 20 Feb 2006 13:18 GMT
Bunches of thanks!
But I need a little bit more of help.
What I actually want to do is to get the subkeys under a specific HKCU-key.
I've therefore tried to modify the following line:
rval = RegOpenKeyEx(HKCU, "", 0, KEY_ENUMERATE_SUB_KEYS, handle)
into:
rval = RegOpenKeyEx(HKCU, strKeyPath, 0, KEY_ENUMERATE_SUB_KEYS, handle)
And it looks like it partially works. The problem is that the procedure
continues to repeatdedly "read" the first subkey, it never moves on to the
next.
/BosseH
> Option Explicit
>
[quoted text clipped - 74 lines]
>>>>
>>>> /BosseH