Hi,
I have figured out how to write to the registry but i cant seem to manage to read from it?
I am trying to read from the registry and put the value of a key into the variable of passbuffer2 and then put it into edi

I have the following code but instead of the value of the key i get ABCDEFGHIJK... etc

invoke RegCreateKeyEx,HKEY_LOCAL_MACHINE,addr RegPath,NULL,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS, NULL,addr hKey,addr Disp

.if eax==ERROR_SUCCESS
invoke RegQueryValueEx,hKey,addr RegStringName,NULL,REG_SZ,OFFSET PassBuffer2, SIZEOF PassBuffer2
invoke RegCloseKey, hKey

.else
invoke MessageBox,NULL,addr ErrorMsg,addr ErrorMsg,MB_OK or MB_ICONEXCLAMATION
.endif

push PassBuffer2
pop
Posted on 2001-10-26 05:33:25 by Kezza
U must use RegQueryValueEx twice. This is content of registry.asm which I am using often. Sorry for Czech comments. I am so lazy to rewrite it into english. :-)


;Napsano dne 10.9.1999 by GED
;Funkce RegNactiHodnotu nacte hodnotu z registru
;urcenou klicem a Nazvem. Vraci v "offset buffer" nactenou hodnotu.
;
;Priklad:
;.data
;JmenoKlice db "Software\EasyKey",0
;JmenoNazvu db "Options",0
;invoke RegNactiHodnotu, addr JmenoKlice, addr JmenoNazvu
;invoke MessageBox,NULL,offset buffer, addr JmenoNazvu, MB_OK
;
;-----------------------------------------------------------------------
;Funkce RegUlozHodnotu ulozi hodnotu "Hodnota" do registru
;urcenou klicem a Nazvem
;
;Priklad:
;.data
;JmenoKlice db "Software\EasyKey",0
;JmenoNazvu db "Options",0
;JmenoHodnoty db "Vychozi",0
;invoke RegNactiHodnotu, addr JmenoKlice, addr JmenoNazvu, addr JmenoHodnoty
;-----------------------------------------------------------------------
.386
.model flat,stdcall
option casemap:none
;include \Lang\masm32\include\windows.inc
;include \Lang\masm32\include\kernel32.inc
;include \Lang\masm32\include\advapi32.inc
;includelib \Lang\masm32\lib\kernel32.lib
;includelib \Lang\masm32\lib\advapi32.lib

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\advapi32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\advapi32.lib
include registry.inc

.data
equis dd 200

.data?
Hand dd ?
Error db ?
.code
;----------------------------------------------------------------------------------------------
RegNactiHodnotu proc Klic:DWORD, Nazev:DWORD, buff:DWORD
;otevreni klice:
invoke RegOpenKeyEx,HKEY_LOCAL_MACHINE, Klic, NULL, KEY_READ or KEY_SET_VALUE, offset Hand
;zjisteni delky hodnoty
invoke RegQueryValueEx, Hand, Nazev, NULL, NULL, NULL, offset equis
;zjisteni hodnoty
invoke RegQueryValueEx,Hand, Nazev, NULL, NULL, buff,offset equis

;uzavreni registru
invoke RegCloseKey,Hand
ret
RegNactiHodnotu endp

;----------------------------------------------------------------------------------------------
RegUlozHodnotu proc Klic:DWORD, Nazev:DWORD, Hodnota:DWORD
;otevreni klice:
invoke RegOpenKeyEx,HKEY_LOCAL_MACHINE, Klic, NULL, KEY_READ or KEY_SET_VALUE, offset Hand
;zjisteni delky hodnoty k ulozeni
invoke lstrlen, Hodnota
add eax,1;zde pricitam 1, protoze musim zapocitat i nulu ktera ukoncuje tento retezec
;ulozeni hodnoty
invoke RegSetValueEx,Hand,Nazev, NULL, REG_SZ,Hodnota, eax
;uzavreni registru
invoke RegCloseKey,Hand
ret
RegUlozHodnotu endp
end
Posted on 2001-10-26 06:58:51 by gedik

U must use RegQueryValueEx twice.

You only need to call RegQueryKeyEx the second time if the first call returns ERROR_MORE_DATA, i.e. your buffer in the first call was not large enough.

Kezza: where is the string 'ABCDEF...' coming from? Is it in your registry, but in a different key to what you are looking at? Is it the initial data in your buffer? What should the value of the key be? What is the name of the key?
Posted on 2001-10-26 07:12:02 by sluggy

invoke RegQueryValueEx,hKey,addr RegStringName,NULL,REG_SZ,OFFSET PassBuffer2, SIZEOF PassBuffer2


Your last parm must point to an address of the data buffer size.

e.g.



lpcbData dd ?
invoke lstrlen, addr PassBuffer2
mov lpcbData, eax
invoke RegQueryValueEx,hKey,addr RegStringName,NULL,REG_SZ,OFFSET PassBuffer2, addr lpcbData


Ewayne
Posted on 2001-10-26 20:33:49 by Ewayne
I have tried to change gediks code to do what i want it to do and Ewayne i think the SIZEOF passbuffer does the same thing?
but i still cant get it to work does anyone else have some source code or anything?
Posted on 2001-11-02 22:29:40 by Kezza
Hi Kezza,

SIZEOF PassBuffer2 does not do the same thing.

Send me your source and I will fix it for you, or
look at my RegDemo on my web site.

Ewayne
Posted on 2001-11-03 00:52:28 by Ewayne
hey ewayne thanx heaps i finally got it working with ur demo :)
Posted on 2001-11-03 02:40:12 by Kezza