function createuser(Nachname,Vorname,Login,Passwort,Anmeldescript, Organisationeinheit:
string; pwdLastSet: boolean): boolean;
var Container : IADsContainer;
NewObject : IADs;
User : IADsUser;
hr : HREsult;
res: boolean;
varpwd: OleVariant;
begin
result:=true;
createou(Organisationeinheit);
try
hr := ADsGetObject('
LDAP://'+formatOU(Organisationeinheit,0,0)+'
DC='+dom1+'
,DC='+dom2,IADsContainer,Container);
if Failed(hr)
then Exit;
NewObject := Container.Create('
User','
CN='+Nachname+'
'+Vorname)
as IADs;
NewObject.QueryInterface(IID_IADsUser, User);
user.Put('
Name',Nachname+'
'+Vorname);
user.Put('
sAMAccountName',Login);
user.Put('
userPrincipalName',Login+'
@'+dom1+'
.'+dom2);
user.Put('
Firstname',Vorname);
user.Put('
LastName', Nachname);
user.Put('
FullName', Vorname+'
'+Nachname);
user.Put('
LoginScript',Anmeldescript);
except on e:
exception do messagedlg('
Benutzer: '+e.
Message,mterror,[mbok],0);
end;
res:=true;
try
User.SetInfo;
except
result:=false;
res:=false;
end;
if res=true
then begin
User.SetPassword(passwort);
user.AccountDisabled:=false;
try
User.SetInfo;
except on e:
exception do result:=false;
end;
if pwdLastSet
then begin
varpwd:=0;
user.Put('
pwdLastSet',varpwd);
try
user.SetInfo;
except
end;
end;
end;
end;
function createOU(organisationsinheit:
string): boolean;
var container: IADsContainer;
ou: IADsOU;
i: integer;
begin
result:=true;
for i:=0
to numou(organisationsinheit)-1
do begin
try
adsgetobject('
LDAP://'+formatOU(organisationsinheit,1,i)+'
DC='+dom1+'
,DC='+dom2, IADsContainer, Container);
ou:=container.Create('
organizationalUnit',formatOU(organisationsinheit,2,i))
as IADsOU;
except
on e:
exception do showmessage('
Fehler beim Erstellen der Organisationseinheit: '+e.
Message);
end;
try
ou.setinfo;
except
result:=false;
end;
end;
end;