using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks; namespace CvNetVideo.Play
{
/// <summary>
/// 目录权限辅助类
/// </summary>
public class DictionaryHelper
{
/// <summary>
/// 需要足够的权限才能执行此操作:Get filepath rights
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static List<FileSystemRights> GetRights(string path)
{
List<FileSystemRights> ret = new List<FileSystemRights>(); DirectorySecurity dirSec = Directory.GetAccessControl(path, AccessControlSections.All);
AuthorizationRuleCollection rules = dirSec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
foreach (FileSystemAccessRule rule in rules)
{
ret.Add(rule.FileSystemRights);
}
return ret;
} //public static void AccessExample() {
// try
// {
// string DirectoryName = "TestDirectory"; // Console.WriteLine("Adding access control entry for " + DirectoryName); // // Add the access control entry to the directory.
// AddDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow); // Console.WriteLine("Removing access control entry from " + DirectoryName); // // Remove the access control entry from the directory.
// RemoveDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow); // Console.WriteLine("Done.");
// }
// catch (Exception e)
// {
// Console.WriteLine(e);
// } // Console.ReadLine();
//} // Adds an ACL entry on the specified directory for the specified account.
public static void AddDirectorySecurity(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.AddAccessRule(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 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); }
}
}

最新文章

  1. QuickRun-快速运行助手
  2. Replication的犄角旮旯(二)--寻找订阅端丢失的记录
  3. Bots(逆元,递推)
  4. Centos 安装 NodeJS
  5. C语言-sizeof()与strlen()的区别【转】
  6. Chrome应用技巧之代码整理。
  7. Vue深度学习(5)-过渡效果
  8. selenium自动化测试在富文本中输入信息的方法
  9. zipkin
  10. C# 应用Excel条件格式(一)
  11. node启动本地服务器
  12. Objective-C ARC下IBOutlet属性是用weak还是strong来修饰
  13. 关于服务器时区BEIST-8、GMT-8、Asia/Shanghai、CST、GMT+8:00等缩写的含义
  14. JSON之Asp.net MVC C#对象转JSON,DataTable转JSON,List&lt;T&gt;转JSON,JSON转List&lt;T&gt;,JSON转C#对象
  15. 本地存储(LocalStorage、SessionStorage、Web SQL Database、Indexed DB)
  16. 在mac上命令行里面如何打开文本编辑器?
  17. ZOJ2725_Digital Deletions
  18. mysql 创建,授权,删除 用户
  19. ListBox绑定一个对象
  20. ThinkPHP5项目目录规划实践

热门文章

  1. JAVA对图片的任意角度旋转,以及镜像操作
  2. ASP入门(十四)-FileSystemObject 对象
  3. 曾经的超级明星类库jQuery未来也许不再会被前端程序猿追捧了!
  4. jquery效果 窗口弹出案例
  5. android中使用spinner组件
  6. iOS 里RGB 配色 UIColor colorWithRed
  7. Core Java-多线程-线程的生命周期
  8. WinForm 之 应用程序开机自启动设置方法
  9. NetCore中使用DynamicExpresso、Z.Expressions、LambdaParser进行安字符串求值
  10. 1051: 手机(MOBILE)