Link to home
Start Free TrialLog in
Avatar of jfkrueger
jfkrueger

asked on

Enumerate NTFS Folder Permissions

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???
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Have you tried cacls?  Not Visual Basic based, but rather old DOS Batch file type thing.
ASKER CERTIFIED SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jfkrueger
jfkrueger

ASKER

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!
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
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.
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...
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...
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.

didja test mine?
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?