views:

11

answers:

1

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?

+1  A: 

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
Ando