Hi I'm trying to set a registry value with RegSetValueEx. I got the address of the key I want to modify through RegEdit and when I call this function the return value is ERROR_SUCCESS so everything should be grand, but according to RegEdit nothings changed.

I also tried to call RegFlushKey thinking that might help, again its returns that it succeded but no affect again.

Can anyone show me an exapmle of how this function should be used, maybe I'm doing something stupid (and since its the registry, potentially deadly)

Posted on 2001-09-01 13:19:04 by Eóin
Ok, I solved this problem myself so I'll post my solution here for others.

First mistake, you cannot pass a string with the full path of a value to RegSetValueEx. You can only pass the value name. To first get into the subkey which contains it you must first open the key with RegOpenKeyEx.

The second mistake I made was in the formatting of the name of the subkey to open. I was using \some_key\some_sub_key when I should have used some_key\some_sub_key\. Ie the slash at the end rather than the start.

So its not too hard. Why don't I include some pseudo code to help people. :grin:

tkey db "Some_Key\Some_Sub_Key\",0
tVal db "Some_Value",0
BufSize dd 128

hKey dd ?
BufType dd ?
Buffer db 128 dup(?)

invoke RegOpenKeyEx,HKEY_CURRENT_USER,addr tkey,0,KEY_EXECUTE,addr hKey
invoke RegQueryValueEx,hKey,addr tVal,0,addr BufType,addr Buffer,addr BufSize

And the end result of that is BufType will hold the value type, BufSize will hold the size and Buffer will hold the value.
Posted on 2001-09-02 06:03:38 by Eóin