Assembles OK, but regedit doesn't want to start after running this. Says regedit fails to initialize.

Thanks.

; creatsub.asm  Create a subkey of an existing registry key
;                    Help from AsmER,
.386
.MODEL FLAT, STDCALL
OPTION CASEMAP: NONE

    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\advapi32.inc

    include \masm32\macros\macros.asm

    includelib  \masm32\lib\kernel32.lib
    includelib  \masm32\lib\user32.lib
    includelib  \masm32\lib\advapi32.lib

.DATA



APPKey        BYTE "Marzipan", 0
SecondKey    BYTE "basement", 0

.DATA?

RegH        PHKEY      ? ; Handle for registry key
SubRegKey    PHKEY      ?

.CODE

Start:

invoke RegOpenKey, HKEY_CURRENT_USER, ADDR APPKey, ADDR RegH  ;to get handle of already created
                                                              ;reg. key. (marzipan)

invoke RegCreateKey, RegH, ADDR SecondKey, SubRegKey  ;to create (>>or open   
                                                  ;already exist<<) sub reg. key

invoke RegCloseKey, ADDR RegH      ; close handle for reg. key
invoke RegCloseKey, ADDR SubRegKey ; close handle for reg. key


invoke ExitProcess, 0

END Start
Posted on 2006-03-13 16:45:35 by skywalker
Well, there are a few problems with you code, first off you should not create a key that is a direct child of HKEY_CURRENT_USER, you should be using "Software\Company\Package" for your software keys. Second in the following line:

invoke RegCreateKey, RegH, ADDR SecondKey, SubRegKey

You should be passing the address of SubRegKey, not the value...

invoke RegCreateKey, RegH, ADDR SecondKey, ADDR SubRegKey

Third in the following lines:

invoke RegCloseKey, ADDR RegH
invoke RegCloseKey, ADDR SubRegKey

you should be passing the values not the addresses...

invoke RegCloseKey, RegH
invoke RegCloseKey, SubRegKey

The documentation at MSDN explains all of this, read it, there are now a large number of posts both here and at masmforum trying to explain this fairly simple API to you, as opposed to being spoonfed it ad infinitum, do a little research.

For the simple read/write that you are doing, SHGetValue and SHSetValue are more than adequate and do not require opening or closing the keys. But if you insist on the long way for a single value...

.data
hRegKey DD 0
SubKey DB "Software\SkyWalker\MyApp",0
value DB "valuename",0
data DB "This is my data",0
Disposition DD 0
cbRead DD 0

.code
invoke RegOpenKeyEx, HKEY_CURRENT_USER, ADDR SubKey, 0, KEY_WRITE, ADDR hRegKey
test eax,eax
jnz @F ; Open failed
invoke RegSetValueEx, , offset value, NULL, REG_SZ, ADDR data,SIZEOF data
invoke RegCloseKey,
@@:


To read it :

invoke RegCreateKeyEx,HKEY_CURRENT_USER,OFFSET SubKey,NULL,NULL,\
  REG_OPTION_NON_VOLATILE,KEY_READ+KEY_WRITE,NULL,ADDR hRegKey,ADDR Disposition
test eax,eax
jnz @F
invoke RegQueryValueEx,,OFFSET value,0,NULL,OFFSET data,ADDR cbRead
invoke RegCloseKey,
@@:
Posted on 2006-03-13 18:58:45 by donkey

Well, there are a few problems with you code, first off you should not create a key that is a direct child of HKEY_CURRENT_USER, you should be using "Software\Company\Package" for your software keys. Second in the following line:


invoke RegCreateKey, RegH, ADDR SecondKey, SubRegKey

You should be passing the address of SubRegKey, not the value...

invoke RegCreateKey, RegH, ADDR SecondKey, ADDR SubRegKey

Third in the following lines:

invoke RegCloseKey, ADDR RegH
invoke RegCloseKey, ADDR SubRegKey

you should be passing the values not the addresses...

invoke RegCloseKey, RegH
invoke RegCloseKey, SubRegKey

The documentation at MSDN explains all of this, read it, there are now a large number of posts both here and at masmforum trying to explain this fairly simple API to you, as opposed to being spoonfed it ad infinitum, do a little research.

For the simple read/write that you are doing, SHGetValue and SHSetValue are more than adequate and do not require opening or closing the keys. But if you insist on the long way for a single value...

.data
hRegKey DD 0
SubKey DB "Software\SkyWalker\MyApp",0
value DB "valuename",0
data DB "This is my data",0
Disposition DD 0
cbRead DD 0

.code
invoke RegOpenKeyEx, HKEY_CURRENT_USER, ADDR SubKey, 0, KEY_WRITE, ADDR hRegKey
test eax,eax
jnz @F ; Open failed
invoke RegSetValueEx, , offset value, NULL, REG_SZ, ADDR data,SIZEOF data
invoke RegCloseKey,
@@:


To read it :

invoke RegCreateKeyEx,HKEY_CURRENT_USER,OFFSET SubKey,NULL,NULL,\
  REG_OPTION_NON_VOLATILE,KEY_READ+KEY_WRITE,NULL,ADDR hRegKey,ADDR Disposition
test eax,eax
jnz @F
invoke RegQueryValueEx,,OFFSET value,0,NULL,OFFSET data,ADDR cbRead
invoke RegCloseKey,
@@:



Thanks, I'll put the positive of your post to good use.





Posted on 2006-03-13 21:53:24 by skywalker
Although I don't agree with how "evlncrn8" put it, I still agree with the fact that you do not need to quote an entire reply, it is a wasteful (and sometimes annoying) redundancy. These are not the old-obsolete inline-index style forums, let the scroll bar do its job :)
Posted on 2006-03-14 04:37:27 by SpooK