Solved

Delete a registry key

Posted on 2006-07-12
5
210 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

617 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