Esempio n. 1
0
        public static Boolean ReplaceDirectorySecurity(string dir, string[] Account, FileSystemRights Rights, AccessControlType ControlType, InheritanceFlags Inherit, PropagationFlags Propagation)
        {
            DirectoryInfo dInfo = new DirectoryInfo(dir);
            DirectorySecurity dSecurity = new DirectorySecurity();

            try
            {
                dSecurity.SetAccessRuleProtection(true, false);
                foreach (string account in Account)
                {
                    dSecurity.ResetAccessRule(new FileSystemAccessRule(account, Rights, Inherit, Propagation, ControlType));
                }
                dInfo.SetAccessControl(dSecurity);
            }
            catch (Exception ex)
            {
                LibraryLogging.Error("unable to ReplaceDirectorySecurity for {0} error {1}", dir, ex.Message);
                return false;
            }

            return true;
        }