Using system;
Using system. directoryservices;
Namespace Test
{
Public partial class createnewaccount: Form
{
Public createnewaccount ()
{
Initializecomponent ();
}
Private void btncreate_click (Object sender, eventargs E)
{
// Create new user information
Try
{
DirectoryEntry AD = new DirectoryEntry ("WinNT: //" + Environment. MachineName + ", computer"); // class DirectoryEntry encapsulates nodes or objects in the Active Directory hierarchy
DirectoryEntry NewUser = AD. Children. Add ("TestName", "User"); // account
NewUser. Invoke ("SetPassWord", new object [] {"111"}); // Password
NewUser. Invoke ("Put", new object [] {"Description", "Test User from. NET "});
NewUser. CommitChanges ();
DirectoryEntry grp;
Grp = AD. Children. Find ("Guests", "group"); // Find () returns the members with the specified name and type in the set.
If (grp! = Null) {grp. Invoke ("Add", new object [] {NewUser. Path. ToString ()});}
MessageBox. Show ("Account Created successfully", "prompt", messageboxbuttons. OK, messageboxicon. information );
}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
}
}
}
}
Class directoryentry encapsulates nodes or objects in the Active Directory hierarchy