I am working on File Associations. I have identified that there is a key called UserChoice
in:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\[ext].
I have been able to read from and write to the UserChoice
key provided that I create it and that it has not already been created by Windows. However, if the UserChoice
key has already been created by Windows, then I need to run as Administrator to get access to the key. My ultimate goal is to delete the UserChoice
key.
I have noted that Windows places a Deny rule on the UserChoice
key which is preventing me from deleting that key. If I can succeed in removing that rule, I believe that I'll be able to delete the UserChoice
key. Here is the code that I have tried:
public static void ShowSecurity(RegistryKey regKeyRoot, string user) {
RegistrySecurity security = regKeyRoot.GetAccessControl(AccessControlSections.All);
foreach (RegistryAccessRule ar in
security.GetAccessRules(true, true, typeof(NTAccount))) {
if (ar.IdentityReference.Value.Contains(User) &&
ar.AccessControlType.ToString().ToLower() == "deny") {
security.RemoveAccessRuleSpecific(ar);
regKeyRoot.SetAccessControl(security);
}
}
}
When Windows creates the UserChoice
key it adds a security rule for the current user of Type Deny; permission: Special. This rule is not inherited and applies to the UserChoice
key only.
With some messing about and running as Administrator I am able to access that RegistryAccessRule
. However even running as Administrator, I cannot remove this rule. I have read somewhere in my research that there is not a programmatic way to do it. I can remove this rule via RegEdit. I can also remove the UserChoice
key using File Types Manager from NirSoft. So I assume there is some way to do this.
Summary: Is there a way that I can remove the Deny rule so that I can delete the UserChoice
key?