By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,475 Members | 954 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,475 IT Pros & Developers. It's quick & easy.

Find groups that a user belongs to

P: n/a
I am trying to write some code that will find all the groups that a user is a member of

Does anyone know how to do this in VB.NET

Thanks in advanc

Matt
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
VJ
Member of all Exchange Groups you mean?

VJ

"Matt" <an*******@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
I am trying to write some code that will find all the groups that a user is a member of.
Does anyone know how to do this in VB.NET?

Thanks in advance

Matt

Nov 20 '05 #2

P: n/a
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]

"Matt" <an*******@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
I am trying to write some code that will find all the groups that a user is a member of.
Does anyone know how to do this in VB.NET?

Thanks in advance

Matt

Nov 20 '05 #3

P: n/a
you can use WMI...

something like

Imports System.Management

....

Dim myDomain As String = "DomainName"
Dim theUser As String = "LookForMe"
Dim query As String = _
"SELECT * FROM Win32_GroupUser " + _
"WHERE PartComponent = ""Win32_UserAccount.Domain='" + myDomain +
"',Name='" + theUser + "'"""
Dim selectQuery As New SelectQuery(query)
Dim searcher As New ManagementObjectSearcher(sq)
Dim obj As ManagementObject
For Each obj In searcher.Get()
Debug.WriteLine(obj.GetPropertyValue("GroupCompone nt"))
Next obj
hope this helps

dominique

"Matt" <an*******@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
I am trying to write some code that will find all the groups that a user is a member of.
Does anyone know how to do this in VB.NET?

Thanks in advance

Matt

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.