Pages

Subscribe:

Ads 468x60px

Wednesday, 7 September 2011

Adding new Windows User Account using Active Directory

                                                               
Download Files:
AddUser.zip
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 stringstrConn = AUTHENTICATION_STRING + Environment.MachineName + "," + KEY_COMPUTER;//active directory entry point for above connection stringobjAD = 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 groupobjGrp = objAD.Children.Find(USER_GROUP, "group");//adding new user to groupif (objGrp.Name != "")
{
objGrp.Invoke("Add", 
new object
[] {objNewUser.Path.ToString()});
}
//endif



0 comments:

Post a Comment