Hi all
I need to create active directly users using C#
Creating active directly users
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rekha SinghRank #1,571 · 1K reputationPosted Feb 1, 2010, 12:27 AM EST
{
string strUser = "CN=username";
string strPassword = "ssss#1234";
string strpath = "LDAP://xxxxx.com/OU=xxxx,DC=xxxx,DC=com";
DirectoryEntry de = new DirectoryEntry(strpath);
DirectoryEntries child = de.Children;
DirectoryEntry deuser = child.Add(strUser,"user");
deuser.Properties["sAMAccountName"].Add(strUserId);
deuser.CommitChanges();
SetPassword(deuser, strPassword);
Enable(deuser);
}
private static void SetPassword(DirectoryEntry UE, string password)
{
object[] oPassword = new object[] {password};
object ret = UE.Invoke("SetPassword", oPassword );
UE.CommitChanges();
}
public void Enable(DirectoryEntry dr)
{
ActiveDs.IADsUser user1 = (ActiveDs.IADsUser) dr.NativeObject;
user1.AccountDisabled =false;
dr.CommitChanges();
}