2009-11-03 66 views
2

我有以下代码,应删除用户从某个文件夹的访问。不幸的是,它没有(访问规则保持原样)。没有例外被抛出。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被调用。为什么规则不去?

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

+1

是否有一个父文件夹正在执行您试图删除的规则? – 2009-11-03 19:07:23

+0

这是继承,如果这就是你的意思... – 2009-11-03 19:11:01

回答

4

看看SetAccessRuleProtectionDirectorySecurity类,从阅读it..I会认为你需要..各地

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

发挥它。

+0

我确实相信这是它。这很棒,非常感谢。 – 2009-11-03 20:39:49