zoukankan      html  css  js  c++  java
  • C#修改文件夹权限

    /// <summary>
    ///为文件夹添加users,everyone用户组的完全控制权限
    /// </summary>
    /// <param name="dirPath"></param>
    static void AddSecurityControll2Folder(string dirPath)
    {
        //获取文件夹信息
        DirectoryInfo dir = new DirectoryInfo(dirPath);
        //获得该文件夹的所有访问权限
        System.Security.AccessControl.DirectorySecurity dirSecurity = dir.GetAccessControl(AccessControlSections.All);
        //设定文件ACL继承
        InheritanceFlags inherits = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;
        //添加ereryone用户组的访问权限规则 完全控制权限
        FileSystemAccessRule everyoneFileSystemAccessRule = new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, inherits, PropagationFlags.None, AccessControlType.Allow);
        //添加Users用户组的访问权限规则 完全控制权限
        FileSystemAccessRule usersFileSystemAccessRule = new FileSystemAccessRule("Users", FileSystemRights.FullControl, inherits, PropagationFlags.None, AccessControlType.Allow);
        bool isModified = false;
        dirSecurity.ModifyAccessRule(AccessControlModification.Add, everyoneFileSystemAccessRule, out isModified);dirSecurity.ModifyAccessRule(AccessControlModification.Add, usersFileSystemAccessRule, out isModified);
        //设置访问权限
        dir.SetAccessControl(dirSecurity);
    }

  • 相关阅读:
    openpyxl python操作Excel表格,
    ansible剧本
    ansible基础知识(二)
    ansible基础知识
    Flask-Migrate
    Python3-笔记-B-003-数据结构-元组tuple( )
    Python3-笔记-B-002-数据结构-字典dict{ }
    Python3-笔记-B-001-数据结构-列表list[ ]
    Python3-笔记-A-001-基本语法
    cordova 学习链接
  • 原文地址:https://www.cnblogs.com/xadmin/p/7196044.html
Copyright © 2011-2022 走看看