Solved

Delete a registry key

Posted on 2006-07-12
5
204 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
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

17 Experts available now in Live!

Get 1:1 Help Now