2011年6月28日 星期二

抓取檔案目前的權限狀態

因為要設定檔案的權限
而且不想改變該檔其他帳號的權限
所以用了下方的方式去抓取 以及設定


        private static void SetAccessRule(
            string fileName
            , string accountName
            , FileSystemRights rights
            , AccessControlType controlType)
        {
            var account
                = new NTAccount(accountName);

            var accessRule
                = new FileSystemAccessRule(account, rights, controlType);

            var securityDescriptor
                = new FileSecurity(fileName, AccessControlSections.Access);
         
            var accessRuleCollection
                = securityDescriptor.GetAccessRules(true, true, typeof(NTAccount));
         
            securityDescriptor.SetAccessRule(accessRule);

            File.SetAccessControl(fileName, securityDescriptor);

        }

沒有留言:

張貼留言