2013-07-11 63 views

回答

3

我不完全相信你打算与上述名单做什么,但你基本上可以做的是获得权限属性到预期的目录。

// Variables: 
string folderPath = ""; 
DirectoryInfo dirInfo = null; 
DirectorySecurity dirSec = null; 
int i = 0; 

try 
{ 
    // Read our Directory Path. 
    do 
    { 
      Console.Write("Enter directory... "); 
      folderPath = Console.ReadLine(); 
    } 
    while (!Directory.Exists(folderPath)); 

    // Obtain our Access Control List (ACL) 
    dirInfo = new DirectoryInfo(folderPath); 
    dirSec = dirInfo.GetAccessControl(); 

    // Show the results. 
    foreach (FileSystemAccessRule rule in dirSec.GetAccessRules(true, true, typeof(NTAccount))) 
    { 
      Console.WriteLine("[{0}] - Rule {1} {2} access to {3}", 
      i++, 
      rule.AccessControlType == AccessControlType.Allow ? "grants" : "denies", 
      rule.FileSystemRights, 
      rule.IdentityReference.ToString()); 
     } 
} 
catch (Exception ex) 
{ 
    Console.Write("Exception: "); 
    Console.WriteLIne(ex.Message); 
} 

Console.WriteLine(Environment.NewLine + "..."); 
Console.ReadKey(true); 

这是查询目录来获取它的权限级别一个很简单的例子:你基本上查询这样的可能。你会注意到它也会显示所有账户关联的。这应该编译并将基本上显示您帐户关联目录

我不确定这是否是你问的 - 希望这会有所帮助。

+0

这有帮助,谢谢! – JimDel

+0

@JimDel没问题,很高兴帮忙。 – Greg

相关问题