我目前正在编写一个应用程序,它需要检查给定文件路径的Windows文件系统中当前用户对文件的权限。应用程序是用C# .Net 4.0编写的。我相信我是“在正确的领域”,但我需要帮助“开车回家”。这个问题大致是正确的:Iterate through permissions on a file in the windows file system in C#,但更关心的是多个用户--我关心的是当前用户。
以下是我到目前为止所拥有的:
FileSecurity fsObj = file.GetAccessControl(AccessControlSections.Access);
foreach (FileSystemAccessRule fsar in fsObj.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
{
FileSystemRights fsr = fsar.FileSystemRights;
// examine current fsr for permissions...
}我的目标是确定用户是否对文件有写访问权。
发布于 2015-09-23 14:22:06
我相信这是可以做到的(未经检验):
if ((FileSystemRights.Write & fsar.FileSystemRights) != FileSystemRights.Write)
return false;
return true;https://stackoverflow.com/questions/32741924
复制相似问题