Chris Cata

Chris Cata

  • NA
  • 5
  • 0

Creating a user in Active Directory

Jul 10 2008 10:19 AM

Hi, I'm new here and I just have a couple questions about this code below.  It's not mine so I am not taking any credit for it, however I can't get it to work.  I just had a question as to what may be wrong with the code below and what can be done to fix it.  I had it working literally 2 days ago, but I made some changes and started passing some other data to it(username, email, etc.).  Before I just entered it in manually.

Anyways, some of the errors look like so:

A Device attached to the system is not function(HRESULT: 0x8007001F).  Now I think we all know that doesn't make sense and isn' actually related to the error at hand.  I've done some searching around and others have come up with the same conclusion.  However, paying attention to the line number it errors out on it's NewUser.CommitChanges().    I read somewhere else that it's because I didn't specificy a DN for the user.  How do I do this here?  I am thinking it may have been specified before but when I made some changes I removed the code. 

 

-------------

Try

Dim AD As DirectoryEntry = _

New DirectoryEntry("LDAP://mydomain.com/OU=Users,DC=md,DC=ad,DC=mydomain,DC=com", domain & "\" & loginName, pwd)

Dim NewUser As DirectoryEntry = AD.Children.Add("CN=" & dUsername, "user")

NewUser.Properties("SAMAccountName").Value = dUsername

NewUser.CommitChanges()

NewUser.Invoke("SetPassword", New Object() {dPassword})  <--- Problem appears to be here or...

NewUser.Invoke("Put", New Object() {"Description", "FTP"})

NewUser.CommitChanges()  <---- Or here.

Dim grp As DirectoryEntry

grp = AD.Children.Find("GG FTP Public", "group")

If grp.Name <> "" Then

grp.Invoke("Add", New Object() {NewUser.Path.ToString()})

End If

MessageBox.Show("Account Created Successfully")

Catch ex As Exception

MessageBox.Show(ex.ToString)

End Try


Answers (4)