[英]C# - How to get list of USERs/GROUPs having access to shared folder on a Remote Machine
[英]How can I get a list of Groups and User names for a given folder in C#
我找到了一些代碼,展示了如何獲取給定域中的用戶列表。 但我希望從一個文件夾中獲取名稱。 我的搜索並沒有讓我走得太遠。 下面是我正在尋找的列表的示例。
謝謝
我不完全確定你打算用上面的列表做什么,但你基本上可以做的是獲取目標目錄的權限屬性 。 你基本上可以這樣查詢 :
// 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);
這是查詢目錄以獲取其權限級別的一個非常基本的示例。 您會注意到它也會顯示所有相關的物理帳戶 。 這應該編譯並基本上顯示與目錄 關聯的帳戶 。
我不確定這是不是你問的問題 - 希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.