开发者

List AD Groups with Access to a File or Directory in VB.Net

I'm writing code to parse through a list of file directories and identify which AD groups have access. That info is available in the operating 开发者_开发问答system under the file properties security tab, but I can't find any code examples that retrieve that info in vb.net (or c#). Anyone have code that will do that?


Use the DirectorySecurity class.

From the documentation (Application Development Foundation):

The following code sample (which requires both the System.Security.AccessControl and System.Security.Principal namespaces) demonstrates how to display access rules (DACLs) for a folder; however, the same technique could be used to analyze a file, registry value, or other object:

' 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜