Jon Lennart Aasenden
Jon Lennart Aasenden

Reputation: 4020

Get user's GUID via IAdsUser

For some reason, the GUID returned by IAdsUser.GUID is the same no matter what userobject i inspect. I have also tried using the IAdsUser.get('objectGUID') - but that fails. Does anyone have a working piece of delphi code to get the unique identifier for an AD user? Getting the SID is no problem.

mAddr:='WinNT://' + dom1 + '/' + uid1;

if length(Password)>0 then
mRes:=ADsOpenObject(PChar(mAddr),Username,Password,1,IADsUser,usr) else
mRes:=ADsGetObject(PChar(mAddr), IADsUser, usr);

if (mRes=S_OK) and (usr<>NIL) then
Begin
  ADSIUser.UID:=UserName;
  ADSIUser.FullName:=usr.FullName;
  ADSIUser.Disabled:=usr.AccountDisabled;
  ADSIUser.LockedOut:=usr.IsAccountLocked;
  ADSIUser.GUID:=usr.GUID; //<--- returns the same for ALL users

Upvotes: 1

Views: 1531

Answers (1)

simgar
simgar

Reputation: 618

AFAIK, you can't get the objectGUID via the WinNT:// provider. If you can't use the LDAP:// provider, can you use IADsNameTranslate?

Upvotes: 1

Related Questions