2013-07-11 37 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

相關問題