C#-如何获取有权访问远程计算机上共享文件夹的用户/组列表

May*_*r J 3 c# shared-directory user-permissions

我想用C#编写代码以列出所有有权访问(读/写/完全)服务器上共享文件夹的用户/组。

例如:我有一个共享文件夹\ servername \ MyData。现在,我想列出有权访问此文件夹的用户/组。

Joh*_*ohn 5

这应该使您指向正确的方向,我无法测试它的atm,但应该类似。

private bool CheckAccess(DirectoryInfo directory)
{

    // Get the collection of authorization rules that apply to the current directory
    AuthorizationRuleCollection acl = directory.GetAccessControl().GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier));

    foreach (var rule in acl)
    {
        // do something here
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 使用typeof(System.Security.Principal.NTAccount),我们可以有更友好的IdentityReference(即:BUILTIN\Administrators) (3认同)