Link to home
Start Free TrialLog in
Avatar of talee
talee

asked on

How to modify value data of registry using API

Hi, can anyone tell me how to use the API
 ( RegSetValueEx) to change the registry value data?

I had tried using RegSetValueEx to change the value data.  The result is that a new value is added with my data instead of changing the value that I've specified.  

Example:  Default
<No Name>:REG_NONE <data>

After my function,
<No Name>:REG_NONE <data>
<No Name>:REG_NONE <my data>

My question is, how do I change the above data without adding a new value?  The subkeys and value name I type in should be correct.  Below is the full path to the value I want to change.

HKEY_LOCAL_MACHINE\\SECURITY\\Policy\\
PolAdtEv\\<No Name>

Any sugestion/advice?
Thanks!
ASKER CERTIFIED SOLUTION
Avatar of faster
faster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vinniew
vinniew

<No Name> is your problem.  It's either a key or a value, not in between.

Avatar of talee

ASKER

What I'm trying to say is that the value I see using the regedt32 is <No Name>.  Not like value names such as "LegalNoticeText", but only "<No Name>" and inside this value actually contains the data I want to change.

Thanks!
Every key can have a default value which requires no name.  On my machine, it will appear as "default", maybe that is equivalent to "no name".

Again, if you have any problem, you'd better show your code calling the registry API, then we will know what's exactly your problem.
Avatar of talee

ASKER

int array1[9]= {0x00142101,0x00000000,0x00000002,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000007};

HKEY hKeyPolAdtEv;

RegOpenkeyEx( HKEY_LOCAL_MACHINE,
"SECURITY\\Policy\\PolAdtEv", 0, KEY_ALL_ACCESS
&hKeyPolAdtEv);

RegSetValueEx(hKeyPolAdtEv,"<No Name>", 0 , REG_NONE, (byte * ) array1,sizeof(array1));

RegCloseKey( hKeyPolAdtEv);
The code itself is correct, provided that the key "HKEY_LOCAL_MACHINE\\SECURITY\\Policy\\PolAdtEv" already exist.

However it is very uncommon to use "<No Name>" as the NAME of a value, although it is possible.  I don't know why you choose this name.  But anyway, using your code will set this value, and if you change the array value and execute it again, the value is modified.  So I don't know where's your problem.  If the previous value already exist and can't be overwritten, that is strange, but are you sure the name is "<No Name>"?  Maybe it only appears to be so (e.g. it has some trailing space that you did not notice).
Avatar of talee

ASKER

FYI, the subkeys & value already exist on my system by default.

The <No Name> is the value that I see in the registry.  It's not created by me.  It's created by default.  This value contains the data that I want to set.  I'm using NT workstation 4.00.  If we are using the same version and running on normal PC, your registry should also show the same value under the subkeys that I had specified before....which is <No Name>.  Maybe your "default" is the same as my "<No Name>".  

Currently, I've been trying to change the data of this value, but unsuccessful.  Results in creating another value which is the same name as previous ("<No Name>").  

I've also tried putting different spaces in the value.  But it still creates another value.  Doesn't change the data  I want in that value.
Use NULL instead of "<No Name>" in the following API.

RegSetValueEx(hKeyPolAdtEv,"<No Name>", 0 , REG_NONE, (byte * ) array1,sizeof(array1));
Avatar of talee

ASKER

I  also found out that <No Name> means no need to enter any value or NULL in this morning and finally get my program to work,Thanks a lot for your help and your answer.

regards.