Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

registry delete

Status
Not open for further replies.

scklifasovskiy

Programmer
Nov 12, 2012
57
CA
Hi,
I am reading/writing to the registry using functions GetKey() and SetKey().
How can I remove key from the registry?
 
I found that there is a function DeleteKey() but when i execute it doesn't delete ???
my code : oEnv.olProc.DeleteUserKey( "Test", "\Settings\GeneralSettings")
 
Are you sure the user has permission to delete from the registry? In general, if an API call to access the registry fails, it will return an error reply, but you have to explicitly test for that. It's not clear if you are doing that.

Also, you mentioned DeleteKey(), but your code shows DeleteUserKey(). Which one are you using?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
i understand my mistake now... My goal is to delete keyvalue nopt the whole key... So I need to use DeleteKeyValue()...but having trouble still trying to follow help:
Syntax: DeleteKeyValue(cOptName, cKeyPath, nUserKey)
Return: none
Arguments: cOptName specifies the name of the Registry key option. cKeyPath specifies the path to the Registry key. nUserKey specifies the User key.

So if my keyname is "test"
my path is "HKEY_CURRENT_USER\Software\Info-Sys Software inc.\Settings", "test"
and user key -- "test"

So I run oReg.DeleteKeyValue("test","HKEY_CURRENT_USER\Software\Info-Sys Software inc.\Settings", "test")

What am I doing wrong?
 
or maybe im trying to use wrong function again? :(
Here is what I am trying to do:
Under I have "HKEY_CURRENT_USER\Software\Info-Sys Software inc.\Settings\test" folder I have 10 different keys.
I want to delete one of them...
 
To be honest, I'm not sure what the context is. What are these functions you are using? They're not Windows API calls, as far as I can see, and they're not in the FoxPro Foundation Classes. And what is oEnv.olProc?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
oEnv.olProc is a custom class partially based on a registry...
Let's forget oEnv.olProc, and assume i am using registry class directly.
In a registry i have (left side) --> HKEY_CURRENT_USER\Software\Info-Sys Software inc.\Settings\test
on a right side --> 10 different keys
My goal is to delete one of the keys not whole folder "test"...
 
OK, I think I get it now.

You need to call DeleteKeyValue(), passing these three parameters (in the order shown here):

1. The name of the key value. That's the name you see in RegEdit, in the left-hand column in the right-hand pane.

2. The key path. That's the path to the folder, but without the HKEY_CURRENT_USER or whatever (e.g. "\Software\Info-Sys Software inc.\Settings").

3. HKEY_CURRENT_USER or whatever, as an integer. The integers are defined in REGISTRY.H. (Example: -2147483647).

Give that a try. It's been a while since I used the FFC class, and the above is from memory. If it's not right, you can always check the class's source code.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
thanks Mike but still no go...i'm trying all different combinations but :( i know i have rights as i succefully use DeleteKey() function and able to delete key with no problem, but somehow use of DeleteKeyValue() is unsuccesfull...
 
what i am trying to do is:
read from old key --> create new key with value of old key --> delete old key
THE ONLY ONE THING I CANNOT ACHIEVE IS DELETING OLD KEY
IF EMPTY(oEnv.olProc.GetUserKey( "DisableSplash", "\Settings\GeneralSettings" )) -->OK!
lcKey = oEnv.olProc.GetUserKey( "ShowSplash", "\1\Settings\GeneralSettings" ) -->OK!
oEnv.olProc.SetUserKey( "DisableSplash", lcKey, "\Settings\GeneralSettings" ) -->OK!
*{
**oEnv.olProc.DeleteKeyValue( "ShowSplash","\1\Settings\GeneralSettings",HKEY_CURRENT_USER)
OR
oReg = CreateObject("Registry")
oReg.DeleteKeyValue( "ShowSplash","\1\Settings\GeneralSettings",HKEY_CURRENT_USER)
*}
ENDIF

oEnv.olProc is a class that behaves exactly like registry class i.e GetUserKey() is GetRegKey() and so on... you can test with registry.vcx and i can adapt later no problem

thanks mike
 
OK, I've run your code. I'm seeing the same as you: the value is not being deleted.

The code is returning an error code 161. Unfortunately, I don't know what that means. Does anyone here know how I can find the meaning of the error code (it's the same as the code returned from the RegDeleteValue() API call)?

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I've got it to work. I simply removed the leading backslash in the folder name. In other words, instead of this:

Code:
oReg.DeleteKeyValue( "ShowSplash","[b]\[/b]1\Settings\GeneralSettings",HKEY_CURRENT_USER)

I did this:

Code:
oReg.DeleteKeyValue( "ShowSplash","1\Settings\GeneralSettings",HKEY_CURRENT_USER)

Try it, and see if you get the same result.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Obviously the ideal resolution would be to actually Delete the Key Value, but until you get it figured out couldn't you use the SetKey() function to Set the Key Value to an invalid value (such as 0 or '' or whatever) so that your application would not 'see' it as valid?

Good Luck,
JRB-Bldr
 
no.. as it's actually a flag..it could be 1 or 0 as well ... 0 is valid.. ""(blank) -- when key doesn't exist and must be created SetKey() does the job by default.. i gotta figure why it doesn't delete ...
 
it's actually a flag..it could be 1 or 0 as well

If it is your own code, then you can make the 'flag' values anything you want.

If you were to make the 'flag' values something else like 1 or 2, then you could interrogate the value.
If you found a value of 0 you would want to populate it with a VALID value using SetKey()
And if the value was totally absent, then you would need to create the Key and insert a VALID value.

Again, getting the DeleteKey() to work is the ideal approach, but sometimes time constraints, etc. force you to have to move forward in spite of not having the ideal solution.

Just a thought.

Good Luck,
JRB-Bldr
 
application already installed on many clients...i cannot change logic of a flag...
the only thing that i was left with is to do my job but leave old flag behind hanging in a registry..once i will figure whats up with DeleteKeyValue() -- i will write a code in the upgraderoutine and delete it, no big deal

thanks everybody
 
i get no error...just return value is 0 (but with a slash in front it's 161), so the line just doesn't do anything
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top