G
Guest
So I am having some issues with code written by another developer that
interfaces with Active Directory. We had a catastrophic failure on the
server and had to recreate the AD. No the following code does not work:
DirectoryEntry ou = new
DirectoryEntry("LDAP://ou=WISDM,dc=WISDM,dc=wisdm,dc=org", "username",
"password");
// Use the Add method to add a user in an organizational unit.
DirectoryEntry usr = ou.Children.Add("CN=" + fullName,"user");
// Set the samAccountName, then commit changes to the directory.
usr.Properties["samAccountName"].Value = txtLogin.Text;
usr.Properties["givenName"].Value = txtFirstName.Text;
usr.Properties["sn"].Value = txtLastName.Text;
usr.Properties["displayName"].Value = fullName;
usr.Properties["name"].Value = fullName;
usr.Properties["mail"].Value = txtEmail.Text;
usr.Properties["o"].Value = txtCompany.Text;
if(txtStreet.Text!=null && txtStreet.Text.Length > 0)
usr.Properties["streetAddress"].Value = txtStreet.Text;
if(txtCity.Text!=null && txtZip.Text.Length > 0)
usr.Properties["l"].Value = txtCity.Text;
usr.Properties["st"].Value = ddlState.SelectedItem.Value;
if(txtZip.Text!=null && txtZip.Text.Length > 0)
usr.Properties["postalCode"].Value = txtZip.Text;
if(txtPhone.Text!=null && txtPhone.Text.Length > 0)
usr.Properties["telephoneNumber"].Value = txtPhone.Text;
if (ddlRole.SelectedItem.Text.Equals("Guest"))
{
// Set the expiration
//usr.Properties["accountExpires"][0] =
expiresCal.SelectedDate.ToFileTime();
System.Int64 expireTicks = expiresCal.SelectedDate.ToFileTime();
LargeInteger l = new LargeIntegerClass();
l.HighPart = (int) (expireTicks >> 32);
l.LowPart = (int) (expireTicks & 0xFFFFFFFF);
usr.Properties["accountExpires"].Value = l;
}
usr.CommitChanges();
usr.Invoke("SetPassword", new object[]{txtPasswd.Text});
usr.CommitChanges();
usr.Properties["userAccountControl"].Value = 0x10200; // Note: this
value represents don't expire passwd
usr.CommitChanges();
// Add the user to the WISDMUsers Group
DirectoryEntry wisdmUsers = new
DirectoryEntry("LDAP://cn=WISDMUsers,cn=Users,dc=WISDM,dc=wisdm,dc=org",
"username", "password");
wisdmUsers.Invoke("Add", new object[] {usr.Path.ToString()});
}
catch (Exception ex)
{
errorMsg.Text = "Error adding user to Directory: " + ex.Message +
ex.StackTrace;
return;
}
It returns the following error:
Error adding user to Directory: There is no such object on the server at
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at
System.DirectoryServices.DirectoryEntry.Bind() at
System.DirectoryServices.DirectoryEntry.get_IsContainer() at
System.DirectoryServices.DirectoryEntries.CheckIsContainer() at
System.DirectoryServices.DirectoryEntries.Add(String name, String
schemaClassName) at TXDOT_Admin.CreateUser.saveEvent(Object sender, EventArgs
e)
I had to change the connection string to even get this far from
("LDAP://ou=WISDM,dc=WISDM,dc=dalwisdm,dc=org", "username", "password")
to
("LDAP://ou=WISDM,dc=WISDM,dc=wisdm,dc=org", "username", "password")
Any ideas as to obvious things to look for?
interfaces with Active Directory. We had a catastrophic failure on the
server and had to recreate the AD. No the following code does not work:
DirectoryEntry ou = new
DirectoryEntry("LDAP://ou=WISDM,dc=WISDM,dc=wisdm,dc=org", "username",
"password");
// Use the Add method to add a user in an organizational unit.
DirectoryEntry usr = ou.Children.Add("CN=" + fullName,"user");
// Set the samAccountName, then commit changes to the directory.
usr.Properties["samAccountName"].Value = txtLogin.Text;
usr.Properties["givenName"].Value = txtFirstName.Text;
usr.Properties["sn"].Value = txtLastName.Text;
usr.Properties["displayName"].Value = fullName;
usr.Properties["name"].Value = fullName;
usr.Properties["mail"].Value = txtEmail.Text;
usr.Properties["o"].Value = txtCompany.Text;
if(txtStreet.Text!=null && txtStreet.Text.Length > 0)
usr.Properties["streetAddress"].Value = txtStreet.Text;
if(txtCity.Text!=null && txtZip.Text.Length > 0)
usr.Properties["l"].Value = txtCity.Text;
usr.Properties["st"].Value = ddlState.SelectedItem.Value;
if(txtZip.Text!=null && txtZip.Text.Length > 0)
usr.Properties["postalCode"].Value = txtZip.Text;
if(txtPhone.Text!=null && txtPhone.Text.Length > 0)
usr.Properties["telephoneNumber"].Value = txtPhone.Text;
if (ddlRole.SelectedItem.Text.Equals("Guest"))
{
// Set the expiration
//usr.Properties["accountExpires"][0] =
expiresCal.SelectedDate.ToFileTime();
System.Int64 expireTicks = expiresCal.SelectedDate.ToFileTime();
LargeInteger l = new LargeIntegerClass();
l.HighPart = (int) (expireTicks >> 32);
l.LowPart = (int) (expireTicks & 0xFFFFFFFF);
usr.Properties["accountExpires"].Value = l;
}
usr.CommitChanges();
usr.Invoke("SetPassword", new object[]{txtPasswd.Text});
usr.CommitChanges();
usr.Properties["userAccountControl"].Value = 0x10200; // Note: this
value represents don't expire passwd
usr.CommitChanges();
// Add the user to the WISDMUsers Group
DirectoryEntry wisdmUsers = new
DirectoryEntry("LDAP://cn=WISDMUsers,cn=Users,dc=WISDM,dc=wisdm,dc=org",
"username", "password");
wisdmUsers.Invoke("Add", new object[] {usr.Path.ToString()});
}
catch (Exception ex)
{
errorMsg.Text = "Error adding user to Directory: " + ex.Message +
ex.StackTrace;
return;
}
It returns the following error:
Error adding user to Directory: There is no such object on the server at
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at
System.DirectoryServices.DirectoryEntry.Bind() at
System.DirectoryServices.DirectoryEntry.get_IsContainer() at
System.DirectoryServices.DirectoryEntries.CheckIsContainer() at
System.DirectoryServices.DirectoryEntries.Add(String name, String
schemaClassName) at TXDOT_Admin.CreateUser.saveEvent(Object sender, EventArgs
e)
I had to change the connection string to even get this far from
("LDAP://ou=WISDM,dc=WISDM,dc=dalwisdm,dc=org", "username", "password")
to
("LDAP://ou=WISDM,dc=WISDM,dc=wisdm,dc=org", "username", "password")
Any ideas as to obvious things to look for?