I want to retrieve the local group name by which a particular user belongs to. IE, suppose if we know the user and don't know his/her group name in such case i want to retrieve the group name.
-
Are you talking about Windows/Active Directory users? – Swen Kooij May 29 '14 at 11:15
-
yes. Windows. about the local groups and local users. – Aswathy May 29 '14 at 11:20
1 Answers
The same classes/libraries that can be used to retrieve such information for within an Active Directory domain can be used to retrieve this information from the local machine.
You can use the PrincipalContext
class, and related classes to retrieve information about users, groups and much more. The constructor of the PrincipalContext
class allows you to specify a context to search in.
By initializing the PrincipalContext
class like this:
PrincipalContext ctx = new PrincipalContext(ContextType.Machine,Environment.MachineName);
You will operate within your local machine's context. Using the related classes and functions that the PrincipalContext
class exposes, you can accomplish what you want.
Here is a reference on how to get a list of groups a user is a member of:
How to get the groups of a user in Active Directory? (c#, asp.net)
Even though the link above explains how to do this for an active directory. It still uses the PrincipalContext
class. It's just a way of modifying how you initialize the instance.

- 1
- 1

- 985
- 1
- 8
- 18