ディレクトリのアクセス権を取得する

C#でディレクトリのアクセス権を取得します。
ディレクトリのアクセス権を取得する場合にはDirectoryクラスのGetAccessControlメソッドを用います。

  string folderPath = @"C:Windows";
 
  System.Diagnostics.Debug.WriteLine("AreAccessRulesCanonicaltAreAccessRulesProtected");
  textBox1.Text += "AreAccessRulesCanonicaltAreAccessRulesProtected" + "rn";
 
  DirectorySecurity security = Directory.GetAccessControl(folderPath);
  textBox1.Text += security.AreAccessRulesCanonical + 
    "t" + security.AreAccessRulesProtected + "rn";
 
  string ace = "AccessControlTypetAccountNametFileSystemRightstIsInherited"
    +"tInheritanceFlagstPropagationFlags";
  textBox1.Text += ace + "rn";
 
  foreach (FileSystemAccessRule rule in security.GetAccessRules(true, true, typeof(NTAccount))) {
    ace = rule.AccessControlType
        + "t" + (rule.IdentityReference as NTAccount).Value
        + "t" + rule.FileSystemRights.ToString()
        + "t" + rule.IsInherited.ToString()
        + "t" + rule.InheritanceFlags.ToString()
        + "t" + rule.PropagationFlags.ToString();
    System.Diagnostics.Debug.WriteLine(ace);
    textBox1.Text += ace + "rn";
  } 

http://www.ipentec.com/document/document.aspx?page=csharp-get-directory-access-rights&culture=ja-jp

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です