【问题标题】:List AD Groups with Access to a File or Directory in VB.Net在 VB.Net 中列出有权访问文件或目录的 AD 组
【发布时间】:2010-07-06 22:38:51
【问题描述】:

我正在编写代码来解析文件目录列表并确定哪些 AD 组有权访问。该信息在文件属性安全选项卡下的操作系统中可用,但我找不到任何在 vb.net(或 c#)中检索该信息的代码示例。任何人都有代码可以做到这一点?

【问题讨论】:

  • 谢谢安藤。我会接近但错过了 IdentiyReference 方法调用。我真的很感激这一点!如果我可以为你的答案投票两次,我会的!

标签: .net vb.net file active-directory


【解决方案1】:

使用DirectorySecurity 类。

来自文档(应用程序开发基金会):

以下代码示例(其中 既需要 System.Security.AccessControl 和 System.Security.Principal 命名空间) 演示如何显示访问权限 文件夹的规则 (DACL);然而, 相同的技术可用于 分析文件、注册表值,或 其他对象:

' You could also call Directory.GetAccessControl for the following line    
Dim ds As DirectorySecurity = New DirectorySecurity("C:\Program Files", AccessControlSections.Access)
          Dim arc As AuthorizationRuleCollection = ds.GetAccessRules(True, _
          True, GetType(NTAccount))
          For Each ar As FileSystemAccessRule In arc
             Console.WriteLine(ar.IdentityReference.ToString + ": " + _
             ar.AccessControlType.ToString + " " + ar.FileSystemRights.ToString)
          Next

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-18
    • 2012-10-14
    • 1970-01-01
    • 2015-12-22
    • 2014-12-31
    • 2012-02-12
    • 1970-01-01
    相关资源
    最近更新 更多