News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

RegEnumValue problems!!!

Started by xandaz, April 18, 2011, 11:17:22 PM

Previous topic - Next topic

xandaz

   Hi there. I'm trying to make a Regitry Viewing example but things are not going as expected. I know it's been a while since my last post but i'm always hoping for some help. I look around the forum but didn't find much help. From the things i saw here the expected size for Valuename a ValueData is 1024 but sdk says 16383 for data and 255 for name. Can someon check out? ERROR_NO_MORE_ITEMS doesnt seem to work for some of the keys because it keeps adding items to the listview control endlessly.
   Some help pls guys.
   Best regards
   X

hfheatherfox07

Hi I hope you do not find it offensive that I answered your post... I am not sure how to help you but I saw your post and I remembered a MASM example with source like yours that works....so I uploaded it for you... I hope it helps...

I got it here .... Lots of nice stuff here

http://members.a1.net/ranmasaotome/projects.html

there is a solved thread about "ERROR_NO_MORE_ITEMS" right in this forum...Here:
http://www.masm32.com/board/index.php?PHPSESSID=7cff449649ed7bf3a1e0353cc811a50e&topic=11972.0


hfheatherfox07

Sorry the source attachment did not upload ...here it is:

dedndave


xandaz

   Thanks for the help guys. i'm looking into it.
   Best regards from x.

xandaz

   There's an example by donkey in the thread you posted that is quite good. Someone should warn him tho that he should use REG_ENUMERATE_SUB_KEYS for the enumeration process and not KEY_ALL_ACCESS because some of the keys get lost in the process. I've experienced the dame problems. I'm still going around my lil app and things aren't going so well. ´
   Thanks and later guys.
   Best regards from X
   

Gunner

I started a reply yesterday, but got side tracked...

What key are you trying to enumerate? because this will not work...

mov     hCurrentKey,eax
    mov     tvis.item.lParam,eax   
    push    ecx
    invoke  RegEnumKey,hCurrentKey,0,addr szKey,sizeof szKey


hCurrentKey is whatever is in eax?  It should be one of the predefined system keys or a handle to a Parent key you opened with REG_ENUMERATE_SUB_KEYS

after you call RegEnumKey (You should really use RegEnumKeyEx) I would not check for ERROR_SUCCES, I would check for ERROR_NO_MORE_ITEMS...

This is what you need to do:

Open a key with RegOpenKeyEx, save that handle...
Pass that handle to RegEnumKeyEx
Open the key returned and enumerate that key till no more items...
increase the index and call RegEnumKeyEx to get next key... and keep repeating...  don't forget to close the key handles when done...

You don't have to create a big buffer in the data section either... get the handle to the process heap..
Then do the same as above, open key, then RegEnumKeyEx, with the key returned, call RegQueryInfoKey and lpcMaxSubKeyLen will give you the longest key length, HeapAlloc with that number...
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

xandaz

  no gunner. The problem is the value enumeration. Thanks

dedndave

when you enumerate the values under a key, you will not want to forget that there may be sub-keys
in other words, enumerating the values should include enumerating any keys, as well
i use this code to ensure a key is empty before deleting it...
;EDI = 0

;open the key

        push    edi
        INVOKE  RegOpenKeyEx,HKEY_CURRENT_USER,offset dtSubKey,edi,
                KEY_QUERY_VALUE or KEY_SET_VALUE or KEY_ENUMERATE_SUB_KEYS,esp
        or      eax,eax
        pop     ebx                                          ;EBX = hSubKey
        jnz     subkey_does_not_exist

;the first pass ensures there are no subkeys
;the second pass ensures there are no values

        mov     edx,RegEnumKeyEx

Remov1: push    sizeof KeyNameBuffer
        mov     eax,esp
        push    edi
        push    edi
        push    edi
        push    edi
        push    eax
        mov     esi,edx
        push    offset KeyNameBuffer
        push    edi
        push    ebx
        CALL    esi
        cmp     eax,ERROR_NO_MORE_ITEMS
        pop     ecx
        jnz     Remov2

        mov     edx,RegEnumValue
        sub     esi,edx
        jnz     Remov1

;close the key

Remov2: INVOKE  RegCloseKey,ebx
        or      esi,esi
        jnz     key_is_not_empty

        INVOKE  RegDeleteKey,HKEY_CURRENT_USER,offset dtSubKey

key_is_not_empty:
subkey_does_not_exist:


i know that is not exactly what you are looking for, but it should give you some ideas to work with

xandaz

   Dave... why do i need to enumerate the subkeys? i just want to enumerate the values under that particular Key. i don't care about the subkeys. TVN_ITEMEXPANDING takes care of that.
   Thanks guys.
   bests X

xandaz

    Hey...btw... i dont need to use RegQueryValue do I? And also, when looking into the example that donkey made ( it's in the link you posted dave) i saw that he automactically adds a DEFAULT value any key tho it may be empty. Does anyone know why?
   Thanks and laters

dedndave

the (Default) value is always present, and should be enumerated with the others
it has no name, and is sometimes called "the unnamed value"
if you want to find it's value, use a null string as a name (0)
it quite often is unassigned   :P
in win 95, keys only had that one value - they did not have the named values that we are familiar with
or maybe it was win 3 - i forget - lol

xandaz

   Oh, so i should use RegQueryValue with null valuename? Thanks.
   It's partially working already. I had some problems with memalloc functions but things are ok. Only works for reg_bin , reg_dw and reg_sz. Reg_dw has problems, i'm getting wrong valuedata. I must have had wronged the pointers.
   bests X

dedndave

there are some up-to-date constant values
some are in the masm32 windows.inc and some aren't

;       HKEY_CLASSES_ROOT                EQU 80000000h
;       HKEY_CURRENT_USER                EQU 80000001h
;       HKEY_LOCAL_MACHINE               EQU 80000002h
;       HKEY_USERS                       EQU 80000003h
;       HKEY_PERFORMANCE_DATA            EQU 80000004h
;       HKEY_CURRENT_CONFIG              EQU 80000005h
;       HKEY_DYN_DATA                    EQU 80000006h ;missing in MSDN documentation
;       HKEY_CURRENT_USER_LOCAL_SETTINGS EQU 80000007h ;new for win7
;       HKEY_PERFORMANCE_TEXT            EQU 80000050h ;missing in windows.inc
;       HKEY_PERFORMANCE_NLSTEXT         EQU 80000060h ;missing in windows.inc


and for the data types...

;REG_NONE                       EQU 0
; No defined value type.
;
;REG_SZ                         EQU 1
; A null-terminated string. This will be either a Unicode or an ANSI string, depending
; on whether you use the Unicode or ANSI functions.
;
;REG_EXPAND_SZ                  EQU 2
; A null-terminated string that contains unexpanded references to environment variables
; (for example, "%PATH%"). It will be a Unicode or ANSI string depending on whether you
; use the Unicode or ANSI functions. To expand the environment variable references, use
; the ExpandEnvironmentStrings function.
;
;REG_BINARY                     EQU 3
; Binary data in any form.
;
;REG_DWORD                      EQU 4
; A 32-bit number. (aka REG_DWORD_LITTLE_ENDIAN, A 32-bit number in little-endian format.)
;
;REG_DWORD_BIG_ENDIAN           EQU 5
; A 32-bit number in big-endian format.
;
;REG_LINK                       EQU 6
; A null-terminated Unicode string that contains the target path of a symbolic link that
; was created by calling the RegCreateKeyEx function with REG_OPTION_CREATE_LINK.
;
;REG_MULTI_SZ                   EQU 7
; A sequence of null-terminated strings, terminated by an empty string (\0).
; Example: String1\0String2\0String3\0LastString\0\0
; The first \0 terminates the first string, the second to the last \0 terminates the
; last string, and the final \0 terminates the sequence. Note that the final terminator
; must be factored into the length of the string.
;
;REG_RESOURCE_LIST              EQU 8            ;not in windows.inc
; Resource list in the resource map.
;
;REG_FULL_RESOURCE_DESCRIPTOR   EQU 9            ;not in windows.inc
; Resource list in the hardware description.
;
;REG_RESOURCE_REQUIREMENTS_LIST EQU 10           ;not in windows.inc
; Resource requirements list.
;
;REG_QWORD                      EQU 11
; A 64-bit number. (aka REG_QWORD_LITTLE_ENDIAN, A 64-bit number in little-endian format.)

xandaz

   Dave,... RegEnumValue doesnt enumerate default itens except for those with ValueData set to something. Are you sure that those items exist? How do i enumerate those? Can you help out? Thanks
   Bests and later-ons.