.Net下修改文件夹或文件的ACL安全权限
来源:互联网 发布:java jdbc连接池实例 编辑:程序博客网 时间:2024/05/25 19:55
.Net下修改文件夹或文件的ACL安全权限的类:
SetFolderACL:两个重载函数,设置权限的方法,根据需要选择重载。
GetACL: 查看文件夹权限的信息,用户名-权限键值对
GetACLString:查看文件夹权限的文本信息,用户名-权限名键值对
using System;
using System.Collections;
using System.Text;
using System.Security.AccessControl;
using System.IO;
namespace ACL
{
class ACL_FS
{
public static bool SetFolderACL(String FolderPath , String UserName ,
FileSystemRights Rights , AccessControlType AllowOrDeny)
{
InheritanceFlags inherits = InheritanceFlags.ContainerInherit |
InheritanceFlags.ObjectInherit;
return SetFolderACL(FolderPath , UserName , Rights , AllowOrDeny ,
inherits , PropagationFlags.None , AccessControlModification.Add);
}
public static bool SetFolderACL(String FolderPath , String UserName ,
FileSystemRights Rights , AccessControlType AllowOrDeny ,
InheritanceFlags Inherits , PropagationFlags PropagateToChildren ,
AccessControlModification AddResetOrRemove)
{
//过程:获取文件夹安全对象、构造访问规则、修改安全对象的访问规则、重新设置文件夹安全对象
bool ret;
DirectoryInfo folder = new DirectoryInfo(FolderPath);
DirectorySecurity dSecurity = folder.GetAccessControl(AccessControlSections.All);
FileSystemAccessRule accRule = new FileSystemAccessRule(UserName , Rights ,
Inherits , PropagateToChildren , AllowOrDeny);
dSecurity.ModifyAccessRule(AddResetOrRemove , accRule , out ret);
folder.SetAccessControl(dSecurity);
return ret;
}
/// <returns>String,FileSystemRights键值对</returns>
public static Hashtable GetACL(String FolderPath)
{
Hashtable ret = new Hashtable();
DirectorySecurity sec =
Directory.GetAccessControl(FolderPath , AccessControlSections.All);
foreach (FileSystemAccessRule rule in sec.GetAccessRules(true , true ,
typeof(System.Security.Principal.NTAccount)))
{
ret[rule.IdentityReference.ToString()] = rule.FileSystemRights;
}
return ret;
}
public static string GetACLString(String FolderPath)
{
StringBuilder sb = new StringBuilder();
Hashtable rights=GetACL(FolderPath);
foreach (string key in rights.Keys)
{
sb.Append(key + ":/t" + ((FileSystemRights)rights[key]).ToString()+"/r/n");
}
return sb.ToString();
}
}
}
//以上在WindowsXP、Windows Server 2003下测试通过。
转处:hz932
- .Net下修改文件夹或文件的ACL安全权限
- .Net下查看和修改文件夹的ACL安全权限(C#)
- .Net下查看和修改文件夹的ACL安全权限(C#)
- Linux中chmod命令:修改文件或文件夹的权限
- ubuntu修改文件夹或文件权限方法
- Ubuntu修改文件或文件夹权限
- linux下的文件或文件夹的权限
- windows下批量修改文件(或文件夹)权限或所有者
- windows下批量修改文件(或文件夹)权限或所有者
- windows下批量修改文件(或文件夹)权限或所有者
- 如何用chomod或者chown只修改文件夹或只修改文件的权限或所有者
- Ubuntu下如何修改文件或者文件夹的权限
- Ubuntu下如何修改文件或者文件夹的权限
- Ubuntu系统下修改文件/文件夹的访问权限
- ubuntu 修改文件夹下所有文件的权限
- Ubuntu下如何修改文件或者文件夹的权限
- Ubuntu下如何修改文件或者文件夹的权限
- 批量修改文件(或文件夹)权限或所有者
- 在网页中插入flash的时候能在IE中显示但是不能在火狐里显示的问题
- 关于CButton关联整型变量的问题
- VLAN Security White Paper
- 如何将 SQL SERVER 彻底卸载干净
- DPInst and DIfx usage
- .Net下修改文件夹或文件的ACL安全权限
- 网址之家推广
- 关于UpdateData
- 安装SQL SERVER 2005出现“无法在 COM+ 目录中安装和配置程序集”
- 李开复:我的传奇人生源于十句箴言
- [Java 类库]BigDecimal 的使用
- get与set用法
- C#将任意类型数据转成JSON格式输出的类
- 启动VS2010报错:The Environment variable LocalAppData must be manually configured for Windows XP and Windows Server 2003