Solved

Delete a registry key

Posted on 2006-07-12
5
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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