Solved

Enumerate NTFS Folder Permissions

Posted on 2004-10-11
15
1,318 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
didja test mine?
0
 
LVL 2

Author Comment

by:jfkrueger
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

763 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

12 Experts available now in Live!

Get 1:1 Help Now