1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| Dim path As String = "c:\temp"
Dim NtAccountName As String = "MyDomain\MyUserOrGroup"
Dim di As New DirectoryInfo(path)
Dim acl As DirectorySecurity = di.GetAccessControl(AccessControlSections.All)
Dim rules As AuthorizationRuleCollection = acl.GetAccessRules(True, True, GetType(NTAccount))
'Go through the rules returned from the DirectorySecurity
For Each rule As AuthorizationRule In rules
'If we find one that matches the identity we are looking for
If rule.IdentityReference.Value.Equals(NtAccountName, StringComparison.CurrentCultureIgnoreCase) Then
'Cast to a FileSystemAccessRule to check for access rights
If (DirectCast(rule, FileSystemAccessRule).FileSystemRights And FileSystemRights.WriteData) > 0 Then
Console.WriteLine(String.Format("{0} has write access to {1}", NtAccountName, path))
Else
Console.WriteLine(String.Format("{0} does not have write access to {1}", NtAccountName, path))
End If
End If
Next
Console.ReadLine() |