title: RegistrySecurity Access is denied. C#
body: <p>I'm currently having an issue when writing an app to set permissions on some Legacy keys. Legacy keys are quite locked down and to actually modify them in regedit you have to take ownership and then add yourself with full control. When trying to replicate this in code i cannot get the key for write with the error "Access is denied". Example code:</p>
  
  <pre><code>RegistrySecurity rs = new RegistrySecurity();
  rs.AddAccessRule(new RegistryAccessRule("Administrators", RegistryRights.FullControl, AccessControlType.Allow));
  rs.SetOwner(new NTAccount("Administrators"));
  return LocalMachine.CreateSubKey(post, RegistryKeyPermissionCheck.ReadWriteSubTree, rs);
  </code></pre>
  
  <p>Any ideas would be greatly appreciated. I have also tried OpenSubKey with write access requested and I just cannot get the key.</p>
  
  <p>Thanks guys.</p>