Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to modify value data of registry using API

Posted on 1997-07-08
9
Medium Priority
?
358 Views
Last Modified: 2013-12-03
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!
0
Comment
Question by:talee
  • 4
  • 4
9 Comments
 
LVL 7

Accepted Solution

by:
faster earned 80 total points
ID: 1400324
Any value is associated with a name.  As long as you specify an existing name correctly in the API, the value will be replaced.

If you still have no success, show me your code.
0
 
LVL 3

Expert Comment

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

0
 

Author Comment

by:talee
ID: 1400326
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!
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 7

Expert Comment

by:faster
ID: 1400327
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.
0
 

Author Comment

by:talee
ID: 1400328
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);
0
 
LVL 7

Expert Comment

by:faster
ID: 1400329
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).
0
 

Author Comment

by:talee
ID: 1400330
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.
0
 
LVL 7

Expert Comment

by:faster
ID: 1400331
Use NULL instead of "<No Name>" in the following API.

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

Author Comment

by:talee
ID: 1400332
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.  
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question