title: C# - Windows ACL - Applying Inherited Permissions
body: <p>I've been having problems programatically assigning permissions to Folders / Registry entries. I have managed to assign inheriting permissions using the following code:</p>
  <pre><code>FileSystemAccessRule rule = new FileSystemAccessRule(LOGON_USER_NAME,
      FileSystemRights.FullControl, InheritanceFlags.ContainerInherit |
      InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly,
      AccessControlType.Allow);
  
  DirectorySecurity security = new DirectorySecurity(); 
  security.SetAccessRule(rule);
  
  Directory.CreateDirectory(dir);
  Directory.SetAccessControl(dir, security);
  </code></pre>
  <p>This correctly sets my file permissions on all  the child folders i create as an administrator. However, it does not set the permissions on the <code>dir</code> folder itself. I've played around with a fair few permutations for inheritance and propogation, but not had any joy.</p>
  <p>For example, I have:</p>
  <pre><code>dir = %programfiles%\Test
  </code></pre>
  <p>If i have created a folder in test (<code>%programfiles%\Test\SubFolder</code>), I have full permissions assigned to it for my user, but I do not have full permissions on <code>%programfiles%\Test</code>. This is really annoying, as I would like to give my user full permissions to do whatever with the Test directory as well.</p>
  <p>I am having similar problems with registry permissions, but I believe that if i can solve one, i can solve both of the outstanding issues.</p>
  <p>Does anyone know how this can be resolved?</p>
  <p>Regards<br />
  Tris</p>