-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the possibility to enumerate the Users #3
Comments
I think it could be done. However, I'll share an example code that I believe could work. It would need to be tested and adjusted accordingly. procedure GetGroupMembers(const groupName: string);
var
group: IADsGroup;
members: IADsMembers;
member: IUnknown;
enumVar: IEnumVariant;
count: LongWord;
userName, fullName: WideString;
begin
group := ADsGetObject('LDAP://CN=' + groupName + ',OU=UnidadOrganizativa,DC=dominio,DC=com') as IADsGroup;
if Assigned(group) then
begin
members := group.Members as IADsMembers;
members._NewEnum(EnumVar);
EnumVar.Reset;
while EnumVar.Next(1, member, Count) = S_OK do
begin
if Supports(member, IADsUser) then
begin
userName := IADsUser(member).Name;
fullName := IADsUser(member).FullName;
// Add List (userName, fullName)
end;
member := nil;
end;
end;
end; If you would like to contribute to the project, any help would be welcome. |
@gliden |
@EdZava I tried it but there is an OLE-Exception The exception occures in this code |
@gliden function TActiveDirectoryClientWinapi.GetGroupUsers(inDomainName, inGroupName: string; out outUsers: TStringList): Boolean;
var
Path: string;
Resultado: HRESULT;
Group: IADsGroup;
Enum: IEnumVariant;
varUser: OleVariant;
Temp: LongWord;
begin
Result := False;
outUsers := TStringList.Create;
if (Trim(inDomainName) = '') then
Exit;
if (Trim(inGroupName) = '') then
Exit;
Path := TActiveDirectoryWinapiUtils.GetPathLDAP(inDomainName, 'CN=' + inGroupName);
Resultado := ADsGetObject(Path, IADsGroup, Group);
if (Failed(Resultado)) or (Group = nil) then
Exit;
Enum := Group.Members._NewEnum as IEnumVariant;
if (Enum <> nil) then
begin
while (Enum.Next(1, varUser, Temp) = S_OK) do
begin
outUsers.Add(varUser.Name);
VariantClear(varUser);
end;
end;
Result := True;
end; Then tell me if it worked for you. |
@gliden When I have some free time at work, I will try to recover the VM I had with the DA configured to attempt implementing this method. If I find anything else, I will let you know here. |
it would be really helpful if you can enumerate over the users of a specific group
The text was updated successfully, but these errors were encountered: