分不多。c#操作windows2000文件权限问题,高手进
设置一用户读权限的方法如下,还有两个设置读写权限的方法
public bool GrantRootReadAccess(string userName, string fullShopFolder,string []uesrNames)
{
foreach (string theUserName in uesrNames)
{
try
{
string userFullShopName = fullShopFolder + "\\ " + theUserName;
DirectorySecurity security = Directory.GetAccessControl(userFullShopName);
FileSystemAccessRule ruleUser = new FileSystemAccessRule(
new NTAccount(userName), FileSystemRights.Traverse | FileSystemRights.ListDirectory | FileSystemRights.ReadPermissions | FileSystemRights.ReadData | FileSystemRights.Read | FileSystemRights.ExecuteFile | FileSystemRights.WriteAttributes | FileSystemRights.WriteExtendedAttributes, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None,
AccessControlType.Allow);
security.AddAccessRule(ruleUser);
Directory.SetAccessControl(userFullShopName, security);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
continue;
}