首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

分不多。c#操作windows2000文件权限有关问题

2011-12-23 
分不多。c#操作windows2000文件权限问题,高手进设置一用户读权限的方法如下,还有两个设置读写权限的方法pub

分不多。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;
                                }

                        }
                        return   true;


                }

问题是当用户登录时,我怎么获得具体的权限列表,比如说当一用户操作当前文件时,先判断用户有没有读写权限。

[解决办法]
这个可以通过FCL来做
给你点代码:
 // get document's user
FileSecurity sd = File.GetAccessControl(this.textBox1.Text);
foreach (FileSystemAccessRule ace in sd.GetAccessRules(true, true, typeof(NTAccount)))
{
NTAccount name = (NTAccount)ace.IdentityReference;
FileSystemRights right = (FileSystemRights)ace.FileSystemRights;
bool isWrite = ((right | FileSystemRights.Write) == right);
this.textBox2.Text += name.Value + "\r\n";
}
[解决办法]
这个在xp domain下面是可行的。
你右击folder->security可以看到相应的user的权限。

热点排行