开发者

Windows File security, removing an access rule

开发者 https://www.devze.com 2022-12-10 07:52 出处:网络
I have the following code, that should remove the access of users from a certain folder.Unfortunately it doesn\'t (the access rule remains in place).No exception is thrown.

I have the following code, that should remove the access of users from a certain folder. Unfortunately it doesn't (the access rule remains in place). No exception is thrown.

AuthorizationRuleCollection arc = ds.G开发者_JAVA百科etAccessRules(true, true, typeof(NTAccount));

foreach (FileSystemAccessRule ar in arc)
{
    if (ar.IdentityReference is NTAccount)
    {
        NTAccount account = ar.IdentityReference as NTAccount;

        if (!AdminUsers.Contains(account.Value) &&
            ownerAccount != account.Value)
        {
            ds.RemoveAccessRule(ar);
            WriteLog("Removed rule for: " + account);
        }

     }
}

outputDirectory.SetAccessControl(ds);

I can see from my logs that the RemoveAccessRule was called. Why isn't the rule gone?

Edit: The rule is an inherited rule. Do I need to do something different to remove inherited rules?


Take a look at SetAccessRuleProtection on DirectorySecurity class, from reading it..I would think you'd need..

ds.RemoveAccessRule(ar);
ds.SetAccessRuleProtection(true,false);

play around with it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号