[RESOLVED] [2005] groups associated with a folder
I am trying to list all the groups associated with a folder. IE - the ones listed in the security tab in the properties form of a folder.
I have been playing with DirectorySecurity and have so far been unable to find anything to list the various groups. I have found how the replicate / add and remove groups, but so far not how to list them.
I would be grateful for any help what so ever :D
Re: [2005] groups associated with a folder
This seems to work
Private Sub outputACL(ByVal strFolder As String)
'##
'## Code to output the Access Control List (ACL) of a given folder
'##
Dim fs As Security.AccessControl.FileSecurity = System.IO.File.GetAccessControl(strFolder)
Dim user As Security.Principal.NTAccount = CType(fs.GetOwner(GetType(Security.Principal.NTAccount)), Security.Principal.NTAccount)
Dim author As AuthorizationRuleCollection = fs.GetAccessRules(True, True, (GetType(System.Security.Principal.NTAccount)))
frmOutput.txtOutput.Text = "Folder" & vbTab & "Owner" & vbTab & "Perms" & vbTab & "User" & vbTab & _
"Inhertance Flag" & vbTab & "Inherited?" & vbTab & "File System Rights" & vbNewLine
frmOutput.txtOutput.Text = frmOutput.txtOutput.Text & strFolder & vbTab & user.ToString & vbNewLine
For Each Rule As FileSystemAccessRule In author
frmOutput.txtOutput.Text = frmOutput.txtOutput.Text & vbTab & vbTab & Rule.AccessControlType.ToString & vbTab & Rule.IdentityReference.Value & _
vbTab & Rule.InheritanceFlags.ToString & vbTab & Rule.IsInherited & _
vbTab & Rule.FileSystemRights.ToString & vbNewLine
Next
frmOutput.Show()
End Sub
I'll leave it here incase it helps anyone else in the future :D