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.

FileSystemAuditRule2.RemoveFileSystemAuditRuleAll.cs 1.1 KiB

8 vuotta sitten
1234567891011121314151617181920212223242526272829303132333435
  1. using Alphaleonis.Win32.Filesystem;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.AccessControl;
  5. using System.Security.Principal;
  6. namespace Security2
  7. {
  8. public partial class FileSystemAuditRule2
  9. {
  10. public static void RemoveFileSystemAuditRuleAll(FileSystemSecurity2 sd, List<IdentityReference2> accounts = null)
  11. {
  12. var acl = sd.SecurityDescriptor.GetAuditRules(true, false, typeof(SecurityIdentifier));
  13. if (accounts != null)
  14. {
  15. acl.OfType<FileSystemAuditRule>().Where(ace => (accounts.Where(account => account == (IdentityReference2)ace.IdentityReference).Count() > 1));
  16. }
  17. foreach (FileSystemAuditRule ace in acl)
  18. {
  19. sd.SecurityDescriptor.RemoveAuditRuleSpecific(ace);
  20. }
  21. }
  22. public static void RemoveFileSystemAuditRuleAll(FileSystemInfo item, List<IdentityReference2> accounts = null)
  23. {
  24. var sd = new FileSystemSecurity2(item);
  25. RemoveFileSystemAuditRuleAll(sd, accounts);
  26. sd.Write();
  27. }
  28. }
  29. }