I'm unable to take ownership of some keys in the registry with my C# code.
I'm trying take ownership on
Software\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace{1CF1260C-4DD0-4ebb-811F-33C572699FDE}
My app is launched as administrator with the requireAdministrator
flag on the app.manifest
.
UAC is disabled to test without this security that might interfere.
I'm setting the token SeTakeOwnershipPrivilege
properly on my process (Process Explorer confirms me that is enabled on my process).
But when I'm running my code it returns a null key at the OpenSubKey
call.
Here is my method :
public void takeKeyOwnership(RegistryHive root, string path)
{
RegistryKey RootKey = GetKey(root);
var key = RootKey.OpenSubKey(path, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.TakeOwnership);
if(key == null)
{
logger.Warn("[takeKeyOwnership] Unable to take ownership on key " + root + "\\" + path);
return;
}
var acl = key.GetAccessControl(AccessControlSections.None);
var localAdmins = new SecurityIdentifier(Constants.LocalAdministratorsSID);
acl.SetOwner(localAdmins);
key.SetAccessControl(acl);
key.Close();
}
My question is different from : How do I programmatically give ownership of a Registry Key to Administrators? as I've set the SeTakeOwnerShipPrivilege as specified earlier.