I use the following code to create user in Active Directory
DirectoryEntry newUser = null;
try
{
if (!Authenticate()) return null;
newUser = location.Children.Add("CN=" + userName, "user");
newUser.Properties["samAccountName"].Value = userName;
newUser.Properties["cn"].Value = userName;
newUser.CommitChanges();
string guid = newUser.Guid.ToString();
newUser.Invoke("SetPassword", new object[] { password });
newUser.CommitChanges();
DomainDirectoryEntry.Close();
newUser.Close();
return guid;
}
catch
{
throw;
}
finally
{
newUser = null;
}
If I run this code from asp.net web page it create the user in Active Directory and it created disabled but it throw exception Exception has been thrown by the target of an invocation.
and when i get the inner exception of this exception it get me Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDEN
I'm sure that the account that i use to access Active Directory is a full admin ..
I don't determined the reason and why it's create the user but it generate error on setting password ... Could any guide me to get the error ?