首页 新闻 会员 周边

C#编程实现 文件或文件夹访问权限设置 为何不成功?求高手指点。

0
悬赏园豆:20 [待解决问题]

直接看代码:

1             DirectoryInfo di = new DirectoryInfo(@"d:\bb");
2             DirectorySecurity ds = di.GetAccessControl();
3             ds.AddAccessRule(new FileSystemAccessRule("Users",FileSystemRights.FullControl,AccessControlType.Allow));
4             di.SetAccessControl(ds);

(win7系统)执行后,d:\bb文件夹Users用户的权限没任何变化。以管理员身份执行也没效果。不知原因,请亲们指教。

边缘程序员2011的主页 边缘程序员2011 | 初学一级 | 园豆:38
提问于:2014-11-10 19:22
< >
分享
所有回答(3)
0

ds.AddAccessRule(new FileSystemAccessRule("Users", FileSystemRights.FullControl,InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));

Yu | 园豆:12980 (专家六级) | 2014-11-11 13:58

依然不行

支持(0) 反对(0) 边缘程序员2011 | 园豆:38 (初学一级) | 2014-11-13 16:02

@边缘程序员2011: 

http://www.lob.cn/jq/Print.asp?ArticleID=2499

你再按这配置配置

支持(0) 反对(0) Yu | 园豆:12980 (专家六级) | 2014-11-13 20:01
0
// Adds an ACL entry on the specified file for the specified account.
        public static void AddFileSecurity(string fileName, string account, 
            FileSystemRights rights, AccessControlType controlType)
        {
            

            // Get a FileSecurity object that represents the 
            // current security settings.
            FileSecurity fSecurity = File.GetAccessControl(fileName);

            // Add the FileSystemAccessRule to the security settings. 
            fSecurity.AddAccessRule(new FileSystemAccessRule(account,
                rights, controlType));

            // Set the new access settings.
            File.SetAccessControl(fileName, fSecurity);

        }
View Code
Raylin | 园豆:246 (菜鸟二级) | 2014-12-25 16:06
0

给要访问的文件赋予Everyone权限试试

我的地盘听我的 | 园豆:222 (菜鸟二级) | 2015-01-21 09:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册