News:

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

RegSetValueEx isn't working.

Started by Magnum, November 12, 2011, 04:18:19 PM

Previous topic - Next topic

Magnum

RegSetValueEx isn't working.



.DATA

SubKey      BYTE  "Quality_Home_Repair\Customers",0              ;Name of sub key in HKEY_CURRENT_USER
Key_Made    BYTE  "Quality_Home_Repair\Customers created.",0
Failed      BYTE  "Register key NOT sucessfully created.",0
Sample      BYTE  "BOX",0
KeyValue    DWORD  1234            ; Key set to this value

.DATA?

RegH            PHKEY    ?            ; Handle for reg. key
RegBuffer       db       256 dup(?)   ; address of value data

.code

start:

invoke RegCreateKey,HKEY_CURRENT_USER, ADDR SubKey,ADDR RegH

.IF EAX == ERROR_SUCCESS
invoke MessageBox, 0, ADDR Key_Made, ADDR Sample,MB_ICONINFORMATION
.ELSE
; if failed

invoke MessageBox, 0, ADDR Failed, ADDR Sample,MB_ICONINFORMATION

.ENDIF

invoke RegSetValueEx, PHKEY, addr KeyValue,
                              NULL, REG_SZ,
                              addr RegBuffer, sizeof KeyValue

invoke RegCloseKey, PHKEY

invoke RegCloseKey, PHKEY; close handle for reg. key

invoke ExitProcess,0

end start

Have a great day,
                         Andy

dedndave

first, you need to include advapi32 inc/lib for registry functions
        .XCREF
        .NOLIST
        INCLUDE    \masm32\include\masm32rt.inc
        INCLUDE    \masm32\include\advapi32.inc
        INCLUDELIB \masm32\lib\advapi32.lib
        .LIST


second, it's common practice to create your keys as subkeys of HKCU\Software
SubKey      BYTE  "Software\Quality_Home_Repair\Customers",0              ;Name of sub key in HKEY_CURRENT_USER
Key_Made    BYTE  "Software\Quality_Home_Repair\Customers created.",0


you almost had it   :U

Magnum

Have a great day,
                         Andy

dedndave

MY code ????   :lol

let me play with it.....

dedndave

invoke RegSetValueEx, PHKEY, addr KeyValue,
                              NULL, REG_SZ,
                              addr RegBuffer, sizeof KeyValue

invoke RegCloseKey, PHKEY

invoke RegCloseKey, PHKEY; close handle for reg. key

i think, in 3 places, WE need to replace PHKEY with RegH

Magnum

Here is the whole thing.


; Chk_Key_Value.asm Not working
;
.686                                     
.model flat, stdcall                     
option casemap :none                       

include \masm32\include\windows.inc   
include \masm32\include\masm32.inc     

include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\Comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\shell32.inc
include \masm32\include\oleaut32.inc
include \masm32\include\ole32.inc
include \masm32\include\msvcrt.inc
include \masm32\include\advapi32.inc


include \masm32\include\dialogs.inc   
include \masm32\macros\macros.asm     

includelib \masm32\lib\masm32.lib     

includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\Comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\oleaut32.lib
includelib \masm32\lib\ole32.lib
includelib \masm32\lib\msvcrt.lib
includelib \masm32\lib\advapi32.lib

.CONST

;RegSetValueEx isn't working.

.DATA

SubKey      BYTE  "Quality_Home_Repair\Customers",0              ;Name of sub key in HKEY_CURRENT_USER
Key_Made    BYTE  "Quality_Home_Repair\Customers created.",0
Failed      BYTE  "Register key NOT sucessfully created.",0
Sample      BYTE  "BOX",0
KeyValue    DWORD  1234            ; Key set to this value

.DATA?

RegH            PHKEY    ?            ; Handle for reg. key
RegBuffer       db       256 dup(?)   ; address of value data

.code

start:

invoke RegCreateKey,HKEY_CURRENT_USER, ADDR SubKey,ADDR RegH

.IF EAX == ERROR_SUCCESS
invoke MessageBox, 0, ADDR Key_Made, ADDR Sample,MB_ICONINFORMATION
.ELSE
; if failed

invoke MessageBox, 0, ADDR Failed, ADDR Sample,MB_ICONINFORMATION

.ENDIF

invoke RegSetValueEx, PHKEY, addr KeyValue,
                              NULL, REG_SZ,
                              addr RegBuffer, sizeof KeyValue
int 3

invoke RegCloseKey, PHKEY; close handle for reg. key

invoke ExitProcess,0

end start
Have a great day,
                         Andy

dedndave

Sample      BYTE  "BOX",0
ValueName   BYTE  "Test",0                         ;added a value name string here
KeyValue    DWORD  1234            ; Key set to this value

invoke RegSetValueEx, RegH, addr ValueName,
                              NULL, REG_SZ,
                              addr RegBuffer, sizeof KeyValue

dedndave

try this out...

Bill Cravener

Magnum, perhaps my little example will help you to better understand accessing the registry.

http://www.quickersoft.com/examples/Append.zip
My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

Magnum

Have a great day,
                         Andy