Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Retriving a list of permissions based on folder/file

Posted on 2010-11-11
4
Medium Priority
?
312 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Expert Comment

by:MK1978
ID: 34110818
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?
0
 
LVL 2

Expert Comment

by:LTCexpert
ID: 34110821
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
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 34110945
Well, seeing as you seem to be asking for code rather than links to third-party tools, you could try:
' Add these too
' Imports System.IO
' Imports System.Security.Principal
' Imports System.Security.AccessControl

    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

Open in new window

0
 

Author Comment

by:tonelm54
ID: 34118545
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

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question