.NET Framework 2.0 ships with a security library which now allows to comfortably read out Access Control Lists (ACLs) of file system and windows registry. I tryed it out and was impressed how easy it is. See the following code, which prints permissions for a directory.
using System;
using System.Security.AccessControl;
using System.Security.Principal;
using System.IO;
namespace AclTestTool
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < args.Length; i++)
ReadDirectorySecurity(args[i]);
}
static void ReadDirectorySecurity(string sDirName)
{
Console.WriteLine("Directory Security for '" +
sDirName + "'");
DirectoryInfo dirInfo = new DirectoryInfo(sDirName);
DirectorySecurity dirSec = dirInfo.GetAccessControl();
AuthorizationRuleCollection authRuleColl =
dirSec.GetAccessRules(true, false,
typeof(SecurityIdentifier));
foreach (AuthorizationRule authRule in authRuleColl)
{
FileSystemAccessRule accessRule =
(FileSystemAccessRule)authRule;
NTAccount ntAccount = (NTAccount)
authRule.IdentityReference.Translate(
typeof(NTAccount));
Console.WriteLine("{0} (SID={1}): {2} = {3}",
ntAccount.Value, accessRule.IdentityReference,
accessRule.FileSystemRights,
accessRule.AccessControlType);
}
}
}
}
Also check out this!