What language / system are you using?
In C#/.NET, it's really quite simple:
private void ShowGroupMembership(string strUser)
{
DirectoryEntry de = new DirectoryEntry(strUser);
if (de != null)
{
foreach(object oGroup in de.Properties["memberOf"])
{
Console.WriteLine(oGroup.ToString());
}
}
}
If you use C++ or VB on Win32, have a look at the sample under the
"IADsUser" interface documentation, for the "Groups" method.
IADsUser::Groups
The IADsUser::Groups method obtains a collection of the ADSI group
objects to which this user belongs. The method returns an IADsMembers
interface pointer through which you can enumerate all the groups in
the collection.
Example Code [Visual Basic]
The following code example examines the group membership of a user.
Dim usr As IADsUser
On Error GoTo Cleanup
Set usr = GetObject(strUser) // LDAP://cn=YourUser,.....
For Each grp In usr.Groups
Debug.Print grp.Name & " (" & grp.Class & ")"
Next
Cleanup:
If(Err.Number<>0) Then
MsgBox("An error has occurred. " & Err.Number)
End If
Set usr = Nothing
HTH
Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
I want to use the IsMember method. Why does this not work?
Hope it helps,
Bruno
<anon...@discussions.microsoft.com> wrote in message
news:0b3201c39d4c$c9d942c0$a401...@phx.gbl...
I would say that the LDAP provider is indeed broken and should be fixed.
After some additional testing and LDP.exe views of properties, I find that the M$ implementation just sucks.
The WinNT:// provider works as expected. This is probably because the person that wrote the code checked both the Memberof and PrimaryGroup attributes.
LDP clearly shows that the group designated as the "PrimaryGroup" in not listed in the MemberOf attribute.
Yes, finding group membership is maddening. I'll only comment that it can be
done. The method you select depends on your purpose, clients, and
circumstances. If you have no nested groups, you can use the WinNT provider.
If you have nested groups (or don't want to bind with both WinNT and LDAP),
the tokenGroups attribute may be your best bet. Even though code using LDAP
can be much longer, my experience is that it is always faster than WinNT.
Shorter code does not mean faster. I have an IsMember function that uses the
tokenGroups attribute, and reveals membership in nested groups and the
"primary" group at this link:
http://www.rlmueller.net/IsMember4.htm
If you are checking for group membership, you could also hard code the group
Sid and check for a match in the tokenGroups multi-valued attribute. That
would be even faster.
Finally, why do you need to bind to the copy of an object on a particular
DC? The only reason I can think of is to retrieve the value of an attribute
that is not replicated.
--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--
Maybe we need to put the pressure on the .NET team at Microsoft to
incorporate a bit more smarts into the System.DirectoryServices
classes to handle stuff like this for .NET v2.0 :-)
It's really crazy that everyone has to keep inventing these things
again and again......
-Valery.
"Marc Scheuner [MVP ADSI]" <m.sch...@inova.SPAMBEGONE.ch> wrote in message
news:iorupvs1346staepn...@4ax.com...
Still, that is a helpful trick.
Joe K.
"Valery Pryamikov" <Valery.P...@nospam.sm.siemens.no> wrote in message
news:%230afuyf...@tk2msftngp13.phx.gbl...
I will investigate the tokenGroups.
I can not bind with WinNT as this will bind to the PDC emulator which may not be the same DC where the accounts have been created.
Richard
"Howard Bullock" <hbul...@tycoelectronics.com> wrote in message
news:5DD19AEF-E99B-4CFB...@microsoft.com...