Solved

Delete a registry key

Posted on 2006-07-12
5
206 Views
Last Modified: 2010-04-05
Hi.

I've tried 2 ways to delete a registry value with no success.

1st :
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
function RegDelKey(key: HKEY; const path: string) : boolean;
var
  c2 : cardinal;
begin
  result:=false;
  c2:=RegDeleteKey(key,PChar(path));
  if (c2<>ERROR_SUCCESS) and (c2<>2) then
    Application.MessageBox
    (PChar('Error number: '+IntToStr(c2)),PChar('Deleting RegKey "'+path+'"'),0);
  result:=c2=ERROR_SUCCESS;
end;
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~


2nd :
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
var Reg  : TRegistry;

 Reg:=TRegistry.Create;
  Reg.RootKey:=HKEY_CLASSES_ROOT;
  Reg.Access:=KEY_WRITE;
  Reg.DeleteKey(Label1.Caption);//delete the key
  Reg.Free;
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~

The key doesnt go.
Using the function i get an error 5. I think its access denied...
I am an admin so why this happens ?
0
Comment
Question by:CodedK
  • 3
  • 2
5 Comments
 
LVL 16

Author Comment

by:CodedK
ID: 17092240
I meant a registry key, not a value...

This key :
HKEY_CLASSES_ROOT\CLSID\{62D8A3E0-81A4-11d2-8DF3-00A0C9441E20}\ProgID

I want to delete the ProgID
0
 
LVL 16

Author Comment

by:CodedK
ID: 17092252
The ProgID folder has other folders inside thats why it doesnt go so whatshould i do
to delete everything up to ProgId ?
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17092297

If you are running an NT based system, then you will need to use the second version if the key has subkeys. Also, have you tried changing the access on the second version to KEY_ALL_ACCESS? (you need to be able to enumerate the subkeys, if there are any)

Russell
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 250 total points
ID: 17092322
The Reg.DeleteKey ends up calling RegEnumKeyEx, which according to the docs:

>> The key identified by hKey must have been opened with KEY_ENUMERATE_SUB_KEYS access (KEY_READ includes KEY_ENUMERATE_SUB_KEYS). Use the RegCreateKeyEx or RegOpenKeyEx function to open the key.

so the KEY_WRITE access is not going to give it the rights to do it.

---


Russell
0
 
LVL 16

Author Comment

by:CodedK
ID: 17092330
I just added KEY_ALL_ACCESS and it worked.

>> you need to be able to enumerate the subkeys, if there are any

There are other subkeys inside but it worked (XP SP2).
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now