Windows 文件安全,删除访问规则
我有以下代码,应该删除用户对某个文件夹的访问权限。不幸的是,事实并非如此(访问规则仍然存在)。没有抛出异常。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 SetAccessRuleProtection
DirectorySecurity
类,从阅读它..我认为你需要..玩弄它。
Take a look at SetAccessRuleProtection on
DirectorySecurity
class, from reading it..I would think you'd need..play around with it.