How can I get a list of group and user names for a given folder in C #

I found code that shows how to get a list of users in a given domain. But I want to get names from only one folder. My searches do not make me very far. Below is an example of the list I'm looking for.

enter image description here

thanks

+4
source share
1 answer

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.

+3
source

Source: https://habr.com/ru/post/1491012/


All Articles