How to see whether "include inheritable permissions" is unchecked for a file or folder?

I remember using something like this:

DirectoryInfo d = new DirectoryInfo(@"e:\test1");
DirectorySecurity acl = d.GetAccessControl();
if (acl.GetAccessRules(false, true, typeof(System.Security.Principal.SecurityIdentifier)).Count >0)
    // -- has inherited permissions
else
    // -- has no inherited permissions

I was also trying to find a method to check for this but I couldn't find any (even in C++). So I ended up using the code above. It worked like a charm.


C#'s DirectorySecurity class now appears to include the AreAccessRulesProtected property which returns true when inheritance is disabled, and false when inheritance is enabled.

As a result, you can simply use:

DirectorySecurity dirSecurity = Directory.GetAccessControl(pathToDir);
var isInheritanceEnabled = !dirSecurity.AreAccessRulesProtected

Thanks to @Wizou's comment here for the heads-up!