More Security Info on a directory
Posted on 2007-07-23
Thanks to some previous help I got here, I have working code that gets security information on a supplied directory. A sample of the code is below.
There are two things I can't figure out:
1) If one clicks on the Advanced button when viewing security, there are two ticks. "Inherit from parent the permission entries that apply to child objects." and "Replace permissions on all child objects..." How can I read the values of these
2) When changing permissions, there is an option to select "This Folder Only", "Subfolder and Files" etc.
How do I read these values? Its important as a user could have full rights on subfolders, but only read rights on the main folder.
Dim rowPermissions As FolderRightsRow
Dim getInfo As System.IO.DirectoryInfo
getInfo = My.Computer.FileSystem.GetDirectoryInfo(stDirectory)
Dim col As AuthorizationRuleCollection = getInfo.GetAccessControl.GetAccessRules(True, True, Type.GetType("System.Security.Principal.NTAccount"))
For Each rule As AuthorizationRule In col
Dim frule As FileSystemAccessRule = CType(rule, FileSystemAccessRule)
If (frule.FileSystemRights > 0) And (frule.FileSystemRights <= FileSystemRights.FullControl) Then
rowPermissions = dtPermissions.NewRow
rowPermissions.AC_Type = frule.AccessControlType.ToString()
rowPermissions.RightsList = frule.FileSystemRights.ToString()
If (frule.FileSystemRights And FileSystemRights.FullControl) = FileSystemRights.FullControl Then
rowPermissions.FullControl = True