I'm not quite sure what you intend to do with the list above, but what you could essentially do is get the Permission attributes for the intended directory. You could query like this:
// 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);
This is a very simple example of a Directory query for permission levels on it. You will notice that it will display all the physical accounts associated with it. This should compile and essentially show you the accounts associated with the directory.
I am not sure if this is what you asked for. Hope this helps.
source share