How to change registry key acl

delphi package - easy access to security apis
Post Reply
ch1c4um
Posts: 6
Joined: Wed Jun 27, 2012 7:09 pm

How to change registry key acl

Post by ch1c4um »

I need permission to change a registry key for the user Everyone has Full Control access and this way I can delete this key.

I'm using this example

Code: Select all

with RegistrySecurity(HKLM\SYSTEM\ControlSet001\Enum\Root\LEGACY_DMLOAD) do
  begin
    ProtectedDAcl := false;

    DAcl.SetFileAccess(Everyone, True);
    if DAcl.DeleteItems(Everyone) then
      ShowMessage('OK')
    else
      ShowMessage('NOT OK');
  end;
But only modifying this permission and not deleting my key..

I'll use some to clean some keys after uninstall my program
madshi
Site Admin
Posts: 10539
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to change registry key acl

Post by madshi »

Hello,

I'm a bit confused. Your code first adds access for Everyone and then removes it again. Is that intentional? What purpose does that have?

Anyway, the code you're using should more or less work, as long as you have enough privileges to change the ACL. You may have to take ownership first if all else fails. One thing: I'm not sure right now which exact syntax you have to use when feeding a registry path into "RegistrySecurity". It might be safer to call RegOpen/CreateKeyEx() yourself and feed the resulting HKEY into RegistrySecurity.
ch1c4um
Posts: 6
Joined: Wed Jun 27, 2012 7:09 pm

Re: How to change registry key acl

Post by ch1c4um »

Good night my friend, the above code that i posted by mistake the wrong part
if DAcl.DeleteItems (Everyone) disregard the stretch.

I've got to do what i needed, i was only allowed to change and then run the function to remove key TRegistry, and windows XP I had to work with manipulating tokens to work
madshi
Site Admin
Posts: 10539
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to change registry key acl

Post by madshi »

So everything is working fine now?
ch1c4um
Posts: 6
Joined: Wed Jun 27, 2012 7:09 pm

Re: How to change registry key acl

Post by ch1c4um »

okay my friend, thanks for the feedback
Post Reply