You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

36 lines
1.3 KiB

using Alphaleonis.Win32.Filesystem;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Security.Principal;
namespace Security2
{
public partial class FileSystemAccessRule2
{
public static void RemoveFileSystemAccessRuleAll(FileSystemSecurity2 sd, List<IdentityReference2> accounts = null)
{
var acl = sd.SecurityDescriptor.GetAccessRules(true, false, typeof(SecurityIdentifier));
if (accounts != null)
{
acl.OfType<FileSystemAccessRule>().Where(ace => (accounts.Where(account => account == (IdentityReference2)ace.IdentityReference).Count() > 1));
}
foreach (FileSystemAccessRule ace in acl)
{
sd.SecurityDescriptor.RemoveAccessRuleSpecific(ace);
}
}
public static void RemoveFileSystemAccessRuleAll(FileSystemInfo item, List<IdentityReference2> accounts = null)
{
// Only the DACL, so that the owner isn't written back (#34) and the inherited entries keep their flag
var sd = new FileSystemSecurity2(item, AccessControlSections.Access);
RemoveFileSystemAccessRuleAll(sd, accounts);
sd.Write();
}
}
}