Cannot create new user in active directory: I can update user in AD |
|
Author |
Message |
gshah

|
Posted: .NET Base Class Library, Cannot create new user in active directory: I can update user in AD |
Top |
I got following error:
The specified directory service attribute or value does not exist. (Exception from HRESULT: 0x8007200A)
I can update user information but cannot create new one.
Can some suggest what is wrong in this code
Thank you,
public void AddActiveDirectory()
{
try
{
//here thows exception: I need to add in OU=Users new user may be syntax wrong
DirectoryEntry ent = new DirectoryEntry("LDAP://172.19.19.203/CN=Users,DC=gg,DC=com", "gshah", "Ahmedbad1234");
if (ent.SchemaEntry.Name == "container")
{
ent.Children.Add( "CN=Ramesh Shah", "User");
ent.Properties[ "sAMAccountName"].Add("rshah");
ent.Properties[ "username"].Add("rshah");
ent.Properties[ "FirstName"].Value = "Ramesh";
ent.Properties[ "lastname"].Value = "Shah";
ent.Properties[ "displayName"].Value = "Ramesh Shah";
ent.Properties[ "initials"].Value = "RS";
//ent.Properties["sn"].Add("Shah");
//ent.Properties["givenName"].Add("Ramesh");
//ent.Properties["description"].Add("Web Developer");
ent.CommitChanges();
ent.Invoke( "SetPassword", new object[] { "Password123" });
// Create a normal account and enable it - ADS_UF_NORMAL_ACCOUNT
ent.Properties[ "userAccountControl"].Value = 0x200;
ent.CommitChanges();
}
}
catch (Exception Exception1)
{
Console.WriteLine(Exception1.Message);
Log(Exception1.Message, swLog);
}
.NET Development9
|
|
|
|
 |
ahmedilyas

|
Posted: .NET Base Class Library, Cannot create new user in active directory: I can update user in AD |
Top |
I would start by commenting out each property but only create the username and password and see if that works, then add each property in one by one and see what happens
try this:
DirectoryEntry theEntry = new DirectoryEntry("LDAP://domain.com,DC=mydomain,DC=com");
DirectoryEntry theUser = theEntry.Children.Add("CN=username", "user");
theUser.Properties["sAMAccountName"].Add(userID);
theUser.Commit();
theUser.Invoke("SetPassword", new object[]{"password"});
untested....see what happens
|
|
|
|
 |
gshah

|
Posted: .NET Base Class Library, Cannot create new user in active directory: I can update user in AD |
Top |
DirectoryEntry theUser = theEntry.Children.Add("CN=username", "user");
Do I need to pass username and password or how to instance create
How to pass in this line username and password
The specified directory object is not bound to a remote resource\r\n"} System.Runtime.InteropServices.ExternalException System.Runtime.InteropServices.COMException
Thank you reviewing my source code.
|
|
|
|
 |
ahmedilyas

|
Posted: .NET Base Class Library, Cannot create new user in active directory: I can update user in AD |
Top |
the username will be the username you are creating. I will see what I can come up with as I said, I don't have an AD but just reading some things and experimenting. I am in the middle of setting up test machines for this purpose
|
|
|
|
 |
gshah

|
Posted: .NET Base Class Library, Cannot create new user in active directory: I can update user in AD |
Top |
Immediate commit create user in add statement.
Thank you for help me out.
DirectoryEntry user = new DirectoryEntry("LDAP://172.19.19.203/CN=Users,DC=altiris,DC=com", "gshah", "Delhi3123");
if (user.SchemaEntry.Name == "container")
{
DirectoryEntry ent = user.Children.Add( "CN=Pinki Sitapura", "User");
ent.Properties[ "sAMAccountName"].Add("psitapura");
ent.Properties[ "givenName"].Add("Pinki"); //First Name
ent.Properties[ "sn"].Add("Sitapura");
ent.Properties[ "initials"].Value = "ps";
ent.Properties[ "displayName"].Value = "Pinki Sitapura";
ent.Properties[ "mail"].Value =
;
ent.Properties[ "userPrincipalName"].Value =
;
ent.CommitChanges();
ent.Properties[ "description"].Add("Web Developer");
ent.Properties[ "physicalDeliveryOfficeName"].Value = "Lindon";// GetBusinessAddressName();
ent.Properties[ "postalAddress"].Value = "588 WEST 400 E."; //GetBusinessAddress();
ent.Properties[ "postalCode"].Value = "84042";//GetPostalCode();
ent.CommitChanges();
ent.Invoke( "SetPassword", new object[] { "Password123" });
ent.CommitChanges();
//// Create a normal account and enable it - ADS_UF_NORMAL_ACCOUNT
ent.Properties[ "userAccountControl"].Value = 0x200;
ent.CommitChanges();
string homeMDB = "CN=Mailbox Store (ISLAB-EX1),CN=First Storage Group,CN=InformationStore,CN=ISLAB-EX1,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=First Organization,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=altiris,DC=com";
CDOEXM.IMailboxStore mailbox;
mailbox = (IMailboxStore)ent.NativeObject;
mailbox.CreateMailbox(homeMDB);
ent.CommitChanges();
Above CreateMailBox fail with error Error Code: 0x80004005.
homeMDB parameter I retrieve from other user who has already created mail box from exchange server interface.
search in Microsoft and I found this KB
A problem is preventing Windows from accurately checking the license for this computer. Error Code: 0x80004005
May be I need help again.
Thank you in advance.
|
|
|
|
 |
MikeTheLunetMan

|
Posted: .NET Base Class Library, Cannot create new user in active directory: I can update user in AD |
Top |
I've got a problem with creating user too, but I'm our company is using MDaemon Mail Server I've got a following:
Code Snippet
DirectoryEntry container, user;
container = new DirectoryEntry("LDAP://77.92.229.4:389/o=lunet, c=US", "username", "password", AuthenticationTypes.ServerBind);
user = container.Children.Add("cn="+fullName, "user"); user.Properties["sAMAccountName"].Add("asd"); user.Properties["givenName"].Add("asd"); user.Properties["sn"].Add("asd"); user.CommitChanges();
It crashes on user.CommitChanges() and gives following error: The attribute type specified to the directory service is not defined. (Exception from HRESULT: 0x8007200C) and this attribute is "sAMAccountName". How can I fix it
|
|
|
|
 |
|
|