Hello everybody,

I wrote the following proc to enumerate all the keys\subkeys under HKEY_LOCAL_MACHINE for examle. It works and displays thousands of keys in a listview window. Problem is it takes 8 minutes to do it on my 350 MHZ machine using Windows 98. Is there a faster method? Also machine seems sluggish after running code a few times. Maybe overflowing stack. I think all handles are closed.

mov lvi.imask,LVIF_TEXT+LVIF_PARAM
push row
pop lvi.iItem
mov lvi.iSubItem,0

mov dwIndex,00h
invoke lstrcpy,ADDR szKeyPath,ADDR szKeyName
invoke RegOpenKeyEx,HKEY_LOCAL_MACHINE,NULL,NULL,\
KEY_ENUMERATE_SUB_KEYS,ADDR hKey

.if eax!=ERROR_SUCCESS
ret
.endif

push dwIndex
push hKey ;save handle

@@:
mov dwSize,0ffh
invoke RegEnumKeyEx,hKey,dwIndex,ADDR szSubKey,\
ADDR dwSize,NULL,NULL,\
NULL,NULL

.if eax==ERROR_NO_MORE_ITEMS
invoke RegCloseKey,hKey

;***********************
;remove last subkey from full path
;by replacing last backspace with NULL character
;***********************

push edi
xor eax,eax
lea edi,szKeyPath
cld
mov ecx,-1
xor eax,eax
repne scasb ;set edi point end string
not ecx ;string length
mov al,5ch
std ;search back until first backspace character
repne scasb ;not searching past start string
add edi,01h

mov al,
.if al!=5ch
;****************
;normal proc exit point
;****************
pop eax ;used to balance stack
invoke RegCloseKey,hKey
ret

.endif

xor eax,eax
stosb ;replace backspace with NULL character
cld
pop edi

pop hKey
pop dwIndex

;****************
;open old key
;****************
invoke RegOpenKeyEx,hKey,NULL,NULL,\
KEY_ENUMERATE_SUB_KEYS,ADDR hKey

.if eax!=ERROR_SUCCESS
invoke RegCloseKey,hKey
;****************
;an error occured
;****************
ret

.endif

jmp @b

.else
inc dwIndex
invoke lstrcat,ADDR szKeyPath,ADDR szBackSlash
invoke lstrcat,ADDR szKeyPath,ADDR szSubKey

;*****************
;filter output, display, etc.
;*****************

;*****************
;dislpay keys\subkeys
;in listview
;*****************
lea eax,szKeyPath
mov lvi.pszText,eax
push row
pop lvi.lParam
invoke SendMessage,hList,LVM_INSERTITEM,0,addr lvi

push dwIndex ;save index
push hKey ;save handle
;****************
;open new key
;****************
invoke RegOpenKeyEx,hKey,ADDR szSubKey,NULL,\
KEY_ENUMERATE_SUB_KEYS,ADDR hKey

.if eax!=ERROR_SUCCESS
invoke RegCloseKey,hKey
;****************
;an error occured
;****************
ret

.endif

mov dwIndex,00h
jmp @b

.endif

.endif

If you know of a better way to do this or faster, please let me know.

best regards,

czDrillard
Posted on 2003-11-30 16:45:05 by czDrillard
well, does regedit take 8 minutes as well? if not, its quite likely you have a bug somewhere.. but where it is i have no idea, i'll have a look later when i wake up ;)
Posted on 2003-11-30 20:02:26 by evlncrn8