Hi all
I need to create active directly users using C#
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rekha SinghPosted Feb 1, 2010, 5:27 AM
{
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();
}