いてづきブログ

情シスでやってみたことの備忘録

ファイルの権限一覧を取得してみるテスト

ファイルの権限一覧を取得してみるテスト


public static List GetAccesivility(string path)
{
List aces = new List();

try
{
//ディレクトリのセキュリティオブジェクト取得
DirectorySecurity security = Directory.GetAccessControl(path);


//アクセス権の列挙
foreach (FileSystemAccessRule rule in
security.GetAccessRules(true, true, typeof(NTAccount)))
{
string ace = string.Empty;
//ace = rule.AccessControlType.ToString ();
//ace += ",";
ace += rule.IdentityReference.Value;
ace += ",";
ace += rule.FileSystemRights.ToString().Replace(',','.');
//ace += ",";
//ace += rule.IsInherited.ToString();
//ace += ",";
//ace += rule.InheritanceFlags.ToString();
//ace += ",";
//ace += rule.PropagationFlags.ToString();

aces.Add(ace);
Console.WriteLine(ace);
}

}
catch (Exception e)
{
aces = new List();
aces.Add("アクセス出来ませんでした");
}
return aces;
}

取得できた権限についてはこちら
FileSystemRights 列挙体 (System.Security.AccessControl)