直接看代码:
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用户的权限没任何变化。以管理员身份执行也没效果。不知原因,请亲们指教。
ds.AddAccessRule(new FileSystemAccessRule("Users", FileSystemRights.FullControl,InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
依然不行
@边缘程序员2011:
http://www.lob.cn/jq/Print.asp?ArticleID=2499
你再按这配置配置
// 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); }
给要访问的文件赋予Everyone权限试试