Get and set permissions on a registry key

delphi package - easy access to security apis
Post Reply
smartins
Posts: 21
Joined: Wed Jun 23, 2004 6:31 pm

Get and set permissions on a registry key

Post by smartins »

I need to get the permissions of a given key (HKEY_CURRENT_USER\Software\Microsoft\Protected Storage System Provider) and then set all the subkeys (HKEY_CURRENT_USER\Software\Microsoft\Protected Storage System Provider\S-1-5-21-842925246-152049171-1060284298-1003) with these same permissions.

Also, how to replace this new permissions with the older ones.

Any ideas on how to accomplish this? I've looked into the docs but with no examples it's a little difficult to get it right.

Thanks,
Steven Martins
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Does the code I gave you via email not work? Here is it again:

Code: Select all

procedure UnprotectHkcu(path: string);
begin
  with RegistrySecurity('HKCU\' + path) do begin
    ProtectedDAcl := false;
    DAcl.SetFileAccess(CurrentUser, true);
  end;
end;

var str : string;
begin
  str := 'Software\Microsoft\Protected Storage System Provider\' +
CurrentUser.SidStr;
  UnprotectHkcu(str);
  UnprotectHkcu(str + '\Data');
  UnprotectHkcu(str +
'\Data\e161255a-37c3-11d2-bcaa-00c04fd929db\e161255a-37c3-11d2-bcaa-00c04fd9
29db');
This code is supposed to work in all OSs - well, in win9x it simply does nothing. But you can execute it everywhere without any problems. Also it doesn't matter whether the paths exist or not. If they don't exist, madSecurity again simply does nothing.
smartins
Posts: 21
Joined: Wed Jun 23, 2004 6:31 pm

Post by smartins »

Actually I just re-tested it and it's working fine.

Thanks. You might just have gained a new customer :)

Steven Martins
Post Reply