Reading NT File & Folder Permissions
I would like to read the NT Security (Read, Write, List, Inherited, blah blah blah) permissions from a file. I already have some code, and can get the names and SIDs, but can’t seem to figure out the actual access bits. I have found how to SET them, but not read.
Here is what I have so far:
Code:
Imports System
Imports System.IO
Imports System.Security
Imports System.Security.AccessControl
Imports System.Security.Permissions
Imports System.Security.Principal
Module modPermissionFunctions
Public Structure ACLInfo
Dim objARCUsers As AuthorizationRuleCollection
Dim objARCSIDs As AuthorizationRuleCollection
Dim objARCPerms As AuthorizationRuleCollection
Dim strOwner As String
Dim strOwnerSID As String
Dim bitError As Boolean
Dim strErrorMessage As String
End Structure
Sub GetFSObjectSecurity(ByRef strFileName As String, ByRef objRules As ACLInfo)
Try
Dim objFileInfo As New FileInfo(strFileName)
Dim objAC As FileSystemSecurity = objFileInfo.GetAccessControl()
With objRules
.strOwner = objAC.GetOwner(GetType(System.Security.Principal.NTAccount)).Value
.strOwnerSID = objAC.GetOwner(GetType(System.Security.Principal.SecurityIdentifier)).Value
.objARCUsers = objAC.GetAccessRules(True, True, GetType(System.Security.Principal.NTAccount))
.objARCSIDs = objAC.GetAccessRules(True, True, GetType(System.Security.Principal.SecurityIdentifier))
.objARCPerms = >>Here is where I need help<<
End With
objRules.bitError = False
Catch ex As Exception
objRules.bitError = True
objRules.strErrorMessage = ex.Message
End Try
End Sub
End Module
Re: Reading NT File & Folder Permissions
What are you trying to do, in the end? Hard to tell by your description