I found some code that shows how to get a list of users in a given domain. But I'm looking to get the names from just a single folder. My searches aren't getting me very far. Below is an example of the list I'm looking for.
Thanks
You can run the below command to list the groups a user is member of. This command prints the details of the given user account. You can find the group membership information in the last two line of this command output. net user userName.
Normally, we can find the list of local users or groups created on a windows system from User Accounts applet in Control Panel, User Accounts in Control Panel. Or, more in detail in Computer Management MMC, which is my favorite place when checking things like this. Users and Groups in Computer Management MMC.
The answer depends on what kind of groups you want to retrieve. The System.DirectoryServices.AccountManagement namespace provides two group retrieval methods: GetGroups - Returns a collection of group objects that specify the groups of which the current principal is a member.
In order to list groups on Linux, you have to execute the “cat” command on the “/etc/group” file. When executing this command, you will be presented with the list of groups available on your system. Use one of the following commands to list groups on your system. But what do the columns of the group file even represent?
I'm not entirely sure what you intend to do with the above list, but what you could essentially do is obtain Permission Attributes to the intended directory. You could essentially 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 basic example of querying the Directory to obtain the permission levels on it. You'll note that it will show all the physical accounts associated as well. This should compile and will essentially show you Accounts Associated to the Directory.
I'm not sure if this is what you were asking about- Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With