Click here to Skip to main content
15,916,371 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Hi, i hope some of you can help me with my problem
Im trying to do an app in C# and visual studio.
I want to add a new user in my Active Directory with this fields (taking the propieties from txtboxes and 1 passwordbox):

NAME (txtname)
LAST NAME (txtlastname)
WINDOWS LOGIN (txtlogin)
EMAIL (txtemail)
COMPANY (txtcompany)
PASSWORD (passwordboxpassword)
DISPLAY NAME (txtdisplayname)

Also,I want to assing the administrator credentials in the code (Adminuser, Adminpassword) to give permission to the software for create the user in AD.

The Structure of my AD is:


1 solution

Share this answer
Emmanuel Cerna 18-Mar-14 16:46pm    
I already read that post, but I really need your help to create my LDAP
from the data that I told you in the post. There's a picture too, so you can understand my AD structure.
CHill60 18-Mar-14 20:07pm    
Just to help you along... If you have already tried something it is a good idea to include that information in your posts. Also, not many of us will go off-site to view images, code etc - it is called being wary of spammers, trolls and hackers. Finally, don't use CAPITALS ... it is considered shouting and most people think it is rude.
If you go back to the post the KEP has given you, and work through it, you should be able to achieve your goal
Emmanuel Cerna 19-Mar-14 18:35pm    
Hi, I'll really appreciate your help...
Im trying to use this code to my visual basic app, to work in my AD
....this is how i addapted to my network...

//this is my button ADD USER
private void Button_Click_1(object sender, RoutedEventArgs e)
string stringDomainName = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
PrincipalContext PrincipalContext4 = new PrincipalContext(ContextType.Domain, stringDomainName,
"LDAP://133.x.x.196/OU=Test,OU=Location,DC=bs,DC=sanluis,DC=net", ContextOptions.SimpleBind, txtadminuser.Text, txtadminpassword.Password);

UserPrincipal UserPrincipal1 = new UserPrincipal(PrincipalContext4,
txtlogin.Text, txtpassword.Password, true);

UserPrincipal1.UserPrincipalName = "PRUEBA USUARIO";
UserPrincipal1.Name = txtnombre.Text;
UserPrincipal1.GivenName = txtnombre.Text;
UserPrincipal1.Surname = txtapellido.Text;
UserPrincipal1.DisplayName = txtnombre.Text + " " + txtapellido.Text;
UserPrincipal1.EmailAddress = txtmail.Text;
UserPrincipal1.EmployeeId = txtid.Text;

When I compile, the Visual Studio dont detect any errors.
But when I execute, it detecs this error:
apparently on the code line:
UserPrincipal UserPrincipal1 = new UserPrincipal(PrincipalContext4,
txtlogin.Text, txtpassword.Password, true);

I hope you can help me to solve this issue. I guess is something about the connection but I really don't know. Thanks for attention!
CHill60 20-Mar-14 6:41am    
Have a look at this link - someone had the same problem and there are a couple of suggested solutions ...[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900