Windows 文件安全,删除访问规则

发布于 2024-08-09 15:53:43 字数 699 浏览 4 评论 0原文

我有以下代码,应该删除用户对某个文件夹的访问权限。不幸的是,事实并非如此(访问规则仍然存在)。没有抛出异常。

AuthorizationRuleCollection arc = ds.GetAccessRules(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);

我可以从日志中看到调用了RemoveAccessRule。为什么规则没有消失?

编辑:该规则是继承的规则。我需要做一些不同的事情来删除继承的规则吗?

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.GetAccessRules(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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

关于从前 2024-08-16 15:53:43

查看 SetAccessRuleProtection DirectorySecurity 类,从阅读它..我认为你需要..

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

玩弄它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文