Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
I have a problem with adding user to AD.
Everytime I got "Access denied" :(

Could someone help me ??

Here is my code:

try
{
const string Domain = "name.domain.pl";
const string Container = "OU=Users,OU=IT,DC=name,DC=domain,DC=pl";
const string Username = "xkorytkad";
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, Domain, Container);
UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, Username);
UserPrincipal UserAD = new UserPrincipal(principalContext, "adAdminLogin", "adAdminPassword", true);
UserAD.UserPrincipalName = "testuser";
UserAD.Name = "testuser";
UserAD.GivenName = "testuser";
UserAD.Surname = "testuser";
UserAD.DisplayName = "testuser";
UserAD.Description = "testuser";
UserAD.Enabled = false;
UserAD.Save();
MessageBox.Show("User added successfully :)");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}



Please help :(
Posted
Comments
ZurdoDev 16-Dec-15 15:24pm    
Access denied means just that, whatever account your code is running as does not have permissions to AD.

1 solution

OK, then how to solve this problem ?
 
Share this answer
 

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