Avatar of tonelm54
tonelm54
 asked on

Retriving a list of permissions based on folder/file

Good morning,
Ive been looking for a while to be able to take a snapshot of one of our server to be able to see what users have access to what files/folders.

I can get a list of all folders and files easily, but does anyone know how I can pass a folder or file into a function and have it return with a list of users/groups and permissions for that folder/file?

Any assistance anyone can provide, would be appriciated.

Thank you
Visual Basic.NET

Avatar of undefined
Last Comment
tonelm54

8/22/2022 - Mon
MK1978

The command that allows this from command prompt is "cacls"

So for checking the permissions for a file:

cacls <filename/path>

this should give you the require information.  Maybe you can incorporate this into your code?
LTCexpert

Download the Sysinternals Suite from here.
http://technet.microsoft.com/en-us/sysinternals/bb842062.aspx
There is an exe call AccessEnum which will show you who has access to any directory / Drive ect.

Hope this helps
ASKER CERTIFIED SOLUTION
Carl Tawn

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
tonelm54

ASKER
Thank you 'carl_tawn', that is exactly what Im looking for.

Ive used your code to also do file security as well, and attached it below, just incase anyone in the future comes across this thread and intrested.

Thank you
Imports System.IO
Imports System.Security.Principal
Imports System.Security.AccessControl



Module Module1

    Sub Main()
        ListDirectorySecurity("u:\Documents")
        ListFileSecurity("U:\Assesment.xls")
    End Sub

    Public Sub ListDirectorySecurity(ByVal directoryName As String)
        Dim di As New DirectoryInfo(directoryName)
        Dim security As DirectorySecurity = di.GetAccessControl()

        Dim rules As AuthorizationRuleCollection = security.GetAccessRules(True, True, GetType(NTAccount))
        For Each rule As FileSystemAccessRule In rules
            Console.WriteLine(" User: {0}", rule.IdentityReference)
            Console.WriteLine(" Type: {0}", rule.AccessControlType)
            Console.WriteLine(" Rights: {0}", rule.FileSystemRights)
            Console.WriteLine(" Inheritance: {0}", rule.InheritanceFlags)
            Console.WriteLine(" Propagation: {0}", rule.PropagationFlags)
            Console.WriteLine(" Inherited? {0}", rule.IsInherited)
            Console.WriteLine()
        Next
    End Sub

    Public Sub ListFileSecurity(ByVal fileName As String)
        Dim di As New FileInfo(fileName)
        Dim security As FileSecurity = di.GetAccessControl()

        Dim rules As AuthorizationRuleCollection = security.GetAccessRules(True, True, GetType(NTAccount))
        For Each rule As FileSystemAccessRule In rules
            Console.WriteLine(" User: {0}", rule.IdentityReference)
            Console.WriteLine(" Type: {0}", rule.AccessControlType)
            Console.WriteLine(" Rights: {0}", rule.FileSystemRights)
            Console.WriteLine(" Inheritance: {0}", rule.InheritanceFlags)
            Console.WriteLine(" Propagation: {0}", rule.PropagationFlags)
            Console.WriteLine(" Inherited? {0}", rule.IsInherited)
            Console.WriteLine()
        Next
    End Sub
End Module

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy