相关疑难解决方法(0)

读取C#中目录的权限

我注意到如果你更改了特定目录的安全设置,你可以在Windows中使该文件夹不再"可浏览".特别是,将管理员的"读取"权限更改为"拒绝"将使该文件夹无法访问.

我现在的问题是,我如何在代码中解决这个问题?我跟着让我接近,但它仍然是不对的:

/// <summary>
/// Takes in a directory and determines if the current user has read access to it (doesn't work for network drives)
/// THIS IS VERY HACKY
/// </summary>
/// <param name="dInfo">directoryInfo object to the directory to examine</param>
/// <returns>true if read access is available, false otherwise</returns>
public static bool IsDirectoryReadable(DirectoryInfo dInfo)
{
    try
    {
        System.Security.AccessControl.DirectorySecurity dirSec = dInfo.GetAccessControl();
        System.Security.Principal.WindowsIdentity self = System.Security.Principal.WindowsIdentity.GetCurrent();
        System.Security.Principal.WindowsPrincipal selfGroup = new System.Security.Principal.WindowsPrincipal(self);
        // Go through each access rule found for the …
Run Code Online (Sandbox Code Playgroud)

c# directory permissions

7
推荐指数
1
解决办法
7632
查看次数

标签 统计

c# ×1

directory ×1

permissions ×1