Solved

Enumerate NTFS Folder Permissions

Posted on 2004-10-11
15
1,321 Views
Last Modified: 2008-01-09
I have been looking everywhere and have not been able to come up with a reasonable solution for this problem.  What I am trying to do is write a program/script that will enumerate through folders and return all of the NTFS permissions for each folder.  Any ideas???
0
Comment
Question by:jfkrueger
  • 6
  • 4
  • 2
15 Comments
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12282645
Have you tried cacls?  Not Visual Basic based, but rather old DOS Batch file type thing.
0
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 125 total points
ID: 12282668
Single DOS command (utilizing two other commands) when run in the CMD.EXE command interpreter will give you the results:

for /f "tokens=1" %a in ('dir /ad /b') do @cacls %a

(If you put that in a batch file, change it so that all %a references are instead %%a (double percent)).

For more info on cacls, execute cacls /? at a command prompt.
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12282672
Oh, and if you want from all directories and sub directories from the directory of execution, just add a /s to the dir part of the command -

for /f "tokens=1" %a in ('dir /ad /b /s') do @cacls %a
0
 
LVL 48

Assisted Solution

by:Mikal613
Mikal613 earned 125 total points
ID: 12282837
http://www.killervb.com/FileSystemLib.aspx

Included are the BackupStreamReader and BackupStreamWriter classes for reading and writing NTFS streams, including permissions, auditing and ownership objects
0
 
LVL 2

Author Comment

by:jfkrueger
ID: 12288095
leew,

That seems like a good idea and I may be able to use it, but I would need to be able specify a directory instead of running it from the current directory.  How would I go about doing this?  

Mikal613 - Thanks for the link, I haven't had time to test it out yet but will do so today and let you know how it worked.

Thanks again!
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12288252
Just modify the dir command between the quotes.  For example,
for /f "tokens=1" %a in ('dir /ad /b /s c:\documents and settings') do @cacls %a
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12288288
Actually, as I think about it, spaces and tabs are considered delimiters unless otherwise specified.  So it'd be best to use this instead:
for /f "tokens=1 delims=" %a in ('dir /ad /b /s' "c:\documents and settings") do @cacls "%a"

The "... delims=" effectively says no delimiters.  Also, enclose directory paths in quotes so they are read as a single directory and not multiple directories if they have spaces.
0
 
LVL 2

Author Comment

by:jfkrueger
ID: 12292188
leew,

I cannot get this to work with a directory specified, but that is OK....I can work around it.  However, I noticed that this works fine on my XP machine but when run on a Windows 2000 PC.  Is it possible that the cacls.exe command works differently on these OS's?

Thanks again...
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12294350
It's possible - I don't have a 2K system handy - will tomorrow - I'll check into this.

What happens when you specify a directory?  I tested it and seemed to work fine for me, so I'd like to help resolve it...
0
 
LVL 2

Author Comment

by:jfkrueger
ID: 12299531
leew,

Using your suggestion to specify a directory: for /f "tokens=1 delims=" %a in ('dir /ad /b /s' "c:\documents and settings") do @cacls "%a"

I get the following message: "The system cannot find the file 'dir /ad /b /s' "C:\documents and settings".

Thanks again for all of your help.

0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12299584
didja test mine?
0
 
LVL 2

Author Comment

by:jfkrueger
ID: 12299625
Mikal613 - I did go to the site and look around, but there is no documentation there and I would have no idea how to use it to get what I want...any suggestions?

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

912 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now