I tried to put some error messages in here.

I had a question though. The docs for RegCreateKey show you how to make nested subdirectories
but then RegDeleteKey says you can't delete a key that has subdirectories. So how do you delete
nested ones.

Is there another API to do that ?

Thanks.

; createkey.asm  Create a registry key    Andy Kennedy
;                        Help from Programmer 1989,AsmGuru62,
;                      "You can't rollerskate in a buffalo herd."
;
;lpSubKey
;
; Points to a null-terminated string specifying the name of the key to delete.
; This parameter cannot be NULL, and the specified key must NOT have subkeys.

.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

SubKey      BYTE "Marzipan",0                ; name of sub key in HKEY_CURRENT_USER
CreateOK    BYTE "Reg key creating OK",0    ; for report
ValueOK      BYTE "Adding registry val. OK",0 ;

Problem      BYTE "Unable to add Registry Key !",0

Sample      BYTE "Sample",0              ; title of message box
NewRegValue  BYTE "Nummer",0              ; Value name
Digit        DWORD 777                    ; This variable will be written to the registry

.DATA?

RegH PHKEY ? ; Handle for registry key

.CODE

Start:

invoke RegCreateKey, HKEY_CURRENT_USER, ADDR SubKey, ADDR RegH ;Create key
.IF EAX == ERROR_SUCCESS ; Error checking

; Code executed, if function succeeds
invoke MessageBox, 0, ADDR CreateOK, ADDR Sample, MB_ICONINFORMATION
invoke RegSetValueEx, RegH, ADDR NewRegValue, 0, REG_DWORD, ADDR Digit, 4

.IF EAX == ERROR_SUCCESS
invoke MessageBox, 0, ADDR ValueOK, ADDR Sample,MB_ICONINFORMATION
.ENDIF

.ELSE
; Code if create function fails
invoke MessageBox, 0, ADDR Problem, ADDR Sample,MB_ICONINFORMATION

.ENDIF

invoke RegCloseKey, ADDR RegH

invoke ExitProcess, 0

END Start
Posted on 2006-03-11 15:03:28 by skywalker
skywalker,

You delete all the subkeys first and then delete the key.  :)

Posted on 2006-03-11 17:46:14 by Greg