I used Active Directory to add new user account. The Active Directory will be accessed using windows native protocol (not LDAP).
The code is like following:
//active directory connection string
strConn = AUTHENTICATION_STRING + Environment.MachineName + "," + KEY_COMPUTER;
//active directory entry point for above connection string
objAD = new DirectoryEntry(strConn);
where strConn is connection string for native (NT) protocol and objAD is Active Directory entry point.
We will add new user using "Invoke" method which access special windows API functions:
objNewUser = objAD.Children.Add(USER_NAME, "user");
objNewUser.Invoke("SetPassword", new object[] {USER_PWD});
objNewUser.Invoke("Put", new object[] {"Description", USER_DESCR});
objNewUser.CommitChanges();
After adding new user in Active Directory we can put this user in a properly group:
//finding group
objGrp = objAD.Children.Find(USER_GROUP, "group");
//adding new user to group
if (objGrp.Name != "")
{
objGrp.Invoke("Add", new object[] {objNewUser.Path.ToString()});
}
//endif
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.
Sonu ChaudharyPosted Feb 25, 2016, 6:40 AM
good one!
G CPosted Jul 18, 2007, 12:50 PM
Hi I create a user account in active directory and set the profile value (fill the "homedirectory" and "homedrive" properties and update user account). When I do this steps in "Active Directory Users and Computers", a folder was created and user access the folder. When I do this with program (mentioned above), properties value is set in active directory but the user folder does not create.Can you help me?