Solved

Enumerate NTFS Folder Permissions

Posted on 2004-10-11
15
1,325 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net 2008 2 60
change vba from autofit to 13.5 width? 4 29
bit defender blocks good applications 2 94
Set email body to html using vbscript 6 41
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

803 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