日期:2014-05-20 浏览次数:21143 次
File.GetAccessControl(filePath)=>FileSecurity
FileSecurity.GetAccessRules(
bool includeExplicit,//true
bool includeInherited,//true
Type targetType//typeof(SecurityIdentifier)
)=>System.Security.AccessControl.AuthorizationRuleCollection
//遍历System.Security.AccessControl.AuthorizationRuleCollection
//检查每个子元素,如果是Full...表示具有所有权限。
File.GetAttributes=>FileAttributes
//此方法无法判断文件是否死锁了
DirectoryInfo dirinfo = new DirectoryInfo(@"c:\test");
System.Security.AccessControl.DirectorySecurity sec = dirinfo.GetAccessControl();
foreach (FileSystemAccessRule rule in sec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
{
Console.WriteLine("----------------------------------");
Console.WriteLine(rule.IdentityReference.Value);
if ((rule.FileSystemRights & FileSystemRights.Read) != 0)
Console.WriteLine(rule.FileSystemRights.ToString());
}
Console.Read();