In order to avoid registry redirection to Wow64 keys, how to translate the following code that uses Microsoft.Win32
APIs
public void SetKeyAccessControl(
RegistryKey rootKey, string subKeyName, string identity,
RegistryRights rights, InheritanceFlags inheritanceFlags,
PropagationFlags propagationFlags, AccessControlType accessType)
{
using (RegistryKey regKey = rootKey.OpenSubKey(subKeyName, true))
{
RegistrySecurity acl = new RegistrySecurity();
RegistryAccessRule rule = new RegistryAccessRule(identity, rights, inheritanceFlags, propagationFlags, accessType);
acl.AddAccessRule(rule);
regKey.SetAccessControl(acl);
}
}
into using advapi32 RegSetKeySecurity API
[DllImport(@"advapi32.dll", EntryPoint = "RegSetKeySecurity", SetLastError = true)]
internal static extern int RegSetKeySecurity(IntPtr handle, uint securityInformation, IntPtr pSecurityDescriptor);
To avoid Registry redirection, you could do something like this...
You can then use rootKey32 or rootKey64 to open a subkey and you'll get the subkey of the view requested.
At least it works in the few test cases I've tried. And, according to the documentation for FromHandle...
Another native method needs to be involved and given an SDDL, the following code sets ACLs on the right registry key: