Popular Posts
Enable edit option in Shutter in Linux sudo apt-get install libgoo-canvas-perl Reference: How To Fix Disabled Edit Option In Shutter in Linux Mint CORS in Asp.net MVC Web API v2 Step 1. Install cors from NeGet Step 2. Enable cors in config using System; using System.Collections.Generic; using System.Linq; using ... DNS SERVER LIST Google 8.8.8.8 8.8.4.4 TWNIC 192.83.166.11 211.72.210.250 HiNet 168.95.1.1 168.95.192.1 Seednet 北區 DNS (台北, 桃園, 新竹, 宜蘭, 花蓮, 苗栗) 139....
Stats
About ACL control.
reference : http://blog.crowe.co.nz/archive/2007/08/25/c---An-example-of-setting-NTFS-Directory--File.aspx
using System.IO;
using System.Security.AccessControl;

namespace Bruce.Lib
{
    public class DirectoryPermissions
    {
        private static void Main(string[] args)
        {
            string ADDomain = "Domain";
            string ADUser = "Chris";
            string Path = @"c:\temp\chris";

            if (Directory.Exists(Path) == false)
                Directory.CreateDirectory(Path);

            // Remove any inheritable permissions from the path 
            RemoveInheritablePermissons(Path);

            // Add the access control entries for the path 
            AddDirectorySecurity(Path, ADDomain + "\\" + ADUser, FileSystemRights.Modify,
                                 InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                                 PropagationFlags.None, AccessControlType.Allow);
            AddDirectorySecurity(Path, ADDomain + "\\Domain Users", FileSystemRights.Delete, InheritanceFlags.None,
                                 PropagationFlags.None, AccessControlType.Deny);
            AddDirectorySecurity(Path, ADDomain + "\\Domain Admins", FileSystemRights.FullControl,
                                 InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                                 PropagationFlags.None, AccessControlType.Allow);
        }


        // Adds an ACL entry on the specified directory for the specified account. 
        public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights,
                                                InheritanceFlags Inheritance, PropagationFlags Propogation,
                                                AccessControlType ControlType)
        {
            // Create a new DirectoryInfo object. 
            DirectoryInfo dInfo = new DirectoryInfo(FileName);
            // Get a DirectorySecurity object that represents the  
            // current security settings. 
            DirectorySecurity dSecurity = dInfo.GetAccessControl();
            // Add the FileSystemAccessRule to the security settings.  
            dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
                                                             Rights,
                                                             Inheritance,
                                                             Propogation,
                                                             ControlType));
            // Set the new access settings. 
            dInfo.SetAccessControl(dSecurity);
        }

        // Removes an ACL entry on the specified directory for the specified account. 
        public static void RemoveDirectorySecurity(string FileName, string Account, FileSystemRights Rights,
                                                   AccessControlType ControlType)
        {
            // Create a new DirectoryInfo object. 
            DirectoryInfo dInfo = new DirectoryInfo(FileName);
            // Get a DirectorySecurity object that represents the  
            // current security settings. 
            DirectorySecurity dSecurity = dInfo.GetAccessControl();
            // Add the FileSystemAccessRule to the security settings.  
            dSecurity.RemoveAccessRule(new FileSystemAccessRule(Account,
                                                                Rights,
                                                                ControlType));
            // Set the new access settings. 
            dInfo.SetAccessControl(dSecurity);
        }

        // Removes an ACL entry on the specified directory for the specified account. 
        public static void RemoveInheritablePermissons(string FileName)
        {
            // Create a new DirectoryInfo object. 
            DirectoryInfo dInfo = new DirectoryInfo(FileName);
            // Get a DirectorySecurity object that represents the  
            // current security settings. 
            DirectorySecurity dSecurity = dInfo.GetAccessControl();
            // Add the FileSystemAccessRule to the security settings. 
            const bool IsProtected = true;
            const bool PreserveInheritance = false;
            dSecurity.SetAccessRuleProtection(IsProtected, PreserveInheritance);
            // Set the new access settings. 
            dInfo.SetAccessControl(dSecurity);
        }

    }
}