以管理员身份运行,如何检查某些Windows帐户是否有权读取目录?

Zvi*_*ika 5 c# security directory

我只获得了帐户用户名(DOMAIN\USER).检查还必须考虑用户的组.我想使用这个示例,但我无法弄清楚如何仅在没有密码的情况下从用户名获取WindowsIdentity.

dan*_*ish 1

您可以使用以下代码:

DirectorySecurity security = directoryInfo.GetAccessControl();
AuthorizationRuleCollection authCollection = security.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));

var username = (from FileSystemAccessRule rule in authCollection
                where rule.IdentityReference.Value == "domain\\username"
                select rule).ToList();
Run Code Online (Sandbox Code Playgroud)