You can query Active Directory. There are plenty of samples on the web, but
only works if you have AD installed.
Or, you can use p/invoke to call the NetUser* functions (primarily
NetUserGetGroups). However, the API functions involved aren't very
..NET-friendly in terms of how they allocate buffers and declare parameter
types.
Alternately, you create a WindowsPrincipal object (there are several samples
in the MSDN help). The WindowsPrincipal object will tell you if a user
belongs to a particular group with the IsInRole method of that object.
Internally, this object keeps a list of group names, but you can only get at
this list by using Reflection (you'll have to bind Instance + NonPublic to
get at it - the list is a private field). Actually, there are two lists (one
array and one hash table if i remember correctly). One list is used if the
user is a member of less than a certain number of groups (20-something i
believe), and the other if the user is a member of more groups.
-Rob Teixeira [MVP]