title: C# code to set a remote share to inherit permissions from its parent directory
body: <p>I have two machines, call them client and server, in a Windows domain. The server has a shared directory which can be accessed from the client machine. I want to run a C# application on the client which sets the permission on this share to inherit the permissions of the share's parent directory on the server. How do I do this?</p>
  
  <p>I have tried code along the following lines, but I don't think it has the right effect:</p>
  
  <pre><code>DirectoryInfo shareDirectoryInfo = new DirectoryInfo("\\server\share");
  DirectorySecurity directorySecurity = shareDirectoryInfo.GetAccessControl();
  directorySecurity.SetAccessRuleProtection(false, false);
  InheritanceFlags iFlags = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;
  FileSystemAccessRule accessRule = new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, iFlags, PropagationFlags.InheritOnly, AccessControlType.Allow);
  bool modified;
  directorySecurity.ModifyAccessRule(AccessControlModification.Set, accessRule, out modified);
  if (modified)
  {
      Directory.SetAccessControl(name, directorySecurity);
  }
  </code></pre>
  
  <p>I guess I don't understand why I have to create a FileSystemAccessRule for the directory - how can I just say inherit from parent?</p>
  
  <p>Thanks for any help! Martin</p>