public bool ValidateFolderPermissions(String windowsAccount, FileSystemRights fileSystemRights, DirectoryInfo folder) { try { var dSecurity = folder.GetAccessControl(); foreach (FileSystemAccessRule rule in dSecurity.GetAccessRules(true, false, typeof(SecurityIdentifier))) { var sid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null); if (sid.CompareTo(rule.IdentityReference as SecurityIdentifier) == 0) { if (fileSystemRights == rule.FileSystemRights) return true; // Validation complete } } return false; } catch (Exception ex) { string msg = "Error validating permissions set on " + folder.FullName + " for the Account \"" + windowsAccount + "\""; Logger.ReportException(msg, ex); MessageBox.Show(msg); return false; } }
public void CompareToNull () { SecurityIdentifier sid = new SecurityIdentifier (WellKnownSidType.BuiltinUsersSid, null); sid.CompareTo ((SecurityIdentifier)null); }