dirEntry.Path = "LDAP://ou=OUMeetingUser, dc=" + DomainSubhead.DomainNameUser;
private void CreateNewuserAccount(string userName, string password) { string oGUID = string.Empty; try { DirectoryEntry dirEntry = new DirectoryEntry(); dirEntry.Path = "LDAP://" + DomainSubhead.DomainNameUser; dirEntry.Username = DomainSubhead.userNameUser; dirEntry.Password = DomainSubhead.PasswordUser; //dirEntry.Parent. DirectoryEntry newUser = dirEntry.Children.Add("CN=" + userName, "user"); //public static string ldapPath = "OU=Domain Users,DC=contoso,DC=com"; newUser.Properties["samAccountName"].Value = userName; newUser.CommitChanges(); oGUID = newUser.Guid.ToString(); newUser.Invoke("SetPassword", new object[] { password }); //----------------------- newUser.Properties["userprincipalname"].Add(userName); // User name (older systems) newUser.Properties["samaccountname"].Add(userName); // Surname newUser.Properties["sn"].Add(userName); // Forename newUser.Properties["givenname"].Add(userName); // Display name newUser.Properties["displayname"].Add(userName); // Description newUser.Properties["description"].Add("description"); // E-mail newUser.Properties["mail"].Add(txtNewUserEmail.Text); int val = (int)newUser.Properties["userAccountControl"].Value; newUser.Properties["userAccountControl"].Value = val & ~0x2; newUser.CommitChanges(); dirEntry.Close(); newUser.Close(); } catch { } }
//ADPath1 = LDAP://172.16.0.1/OU=OUMeetingUser,DC=mydomain,DC=local //ADUser = AD Admin User //ADPassword = AD Admin user's password DirectoryEntry de = new DirectoryEntry(ADPath1, ADUser, ADPassword, AuthenticationTypes.Secure); // 1. Create user account DirectoryEntries users = de.Children; DirectoryEntry newuser = users.Add("CN=" + userid, "user"); //2. Set properties //.... newuser.CommitChanges();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)