Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

Delete a registry key

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
CodedK
Asked:
CodedK
  • 3
  • 2
1 Solution
 
CodedKAuthor Commented:
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
 
CodedKAuthor Commented:
The ProgID folder has other folders inside thats why it doesnt go so whatshould i do
to delete everything up to ProgId ?
0
 
Russell LibbySoftware Engineer, Advisory Commented:

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
 
Russell LibbySoftware Engineer, Advisory Commented:
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
 
CodedKAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now