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
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
Your code did not set KeyValue.
MY code ???? :lol
let me play with it.....
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
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
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
try this out...
Magnum, perhaps my little example will help you to better understand accessing the registry.
http://www.quickersoft.com/examples/Append.zip
Thanks Bill and Dave.