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
Bo Hansson said:
Well, the problem is that I want to do it by means of VBA.code. Any
suggestions?
/BosseH
Jezebel said:
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 Export. This creates a text file ([name].reg) containing a listing
of everything under that root, which you can then filter using Notepad,
Word, Excel or any text editor of your choice.
I would like to get the names of the subdirectories under a certain
directory in the registry.
Is that possible, and if - how do I do that?
/BosseH