-2

I`m working with Active Directory service interfaces and trying to retrieve all users out of a group. I have this line of code which brings me the group itself:

var
  Group:IADSGroup;
begin
  ADsGetObject('LDAP://CN=myGroup,CN=Users,DC=dltomb,DC=dltomb25,DC=com', IADSGroup, Group);
......

the IADSGroup interface has a "IsMember" function that gets a WideString representing a user, and should return true if the user is a member of this group. the problem is that i always get a negative answer from this one... (the user i`m checking is the only user of this group and also checked Group.Count to see that there is one member in this group). if would really like some help regarding this issue, even if someone can point on other workaround such as enumerating the group members (I couldn't do this also)

itay312
  • 1,518
  • 4
  • 24
  • 36

1 Answers1

-1

ok I Found how to iterate the group

var
  groupName: string;
  Fetched: Cardinal;
  ResultItem: OleVariant;
  members: IADsMembers;
..............
groupName:= Group.get_Name;
members:= Group.Members;
enum:= members._NewEnum as IEnumVariant;
Enum.Reset;

Enum.Next(1, ResultItem, Fetched);

while Fetched = 1 do
begin
  GroupMember := IDispatch(ResultItem) as IADS;
  //do something
  Enum.Next(1, ResultItem, Fetched);
end;

But i have another problem now, i can't see all members of the group when adding other members. i red that this is because for some reason it finds only users belong to this group and also that this group is not their primary group. how can i get also a users with the group I`m searching as their primary group?

itay312
  • 1,518
  • 4
  • 24
  • 36
  • Please don't raise a new question in an "answer" - SO doesn't support this. Open a new q instead. – MartynA Nov 17 '16 at 07:48
  • i forgot to add here Enum.Next(1, ResultItem, Fetched); (i fixed it) – itay312 Nov 17 '16 at 09:07
  • It's still not very good because you really should be checking the return value of the call to `Next` as described by the documentation. For example the entire loop could be `Enum.Reset; while Enum.Next(1, ResultItem, Fetched)=S_OK do GroupMember := IDispatch(ResultItem) as IADS; ` – David Heffernan Nov 17 '16 at 09:39