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 = dUsernameNewUser.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 DirectoryEntrygrp = AD.Children.Find(
"GG FTP Public", "group") If grp.Name <> "" Thengrp.Invoke(
"Add", New Object() {NewUser.Path.ToString()}) End IfMessageBox.Show(
"Account Created Successfully") Catch ex As ExceptionMessageBox.Show(ex.ToString)
End Try
Chris CataPosted Jul 17, 2008, 11:22 AM
Well, as a tip then you can try to CommitChanges() at difference stages of the code tos ee what is and isn't work.
djalbert djalbertPosted Jul 17, 2008, 10:20 AM
Chris CataPosted Jul 17, 2008, 9:59 AM
Yes I did. I went back to basics and started to output everything that was getting entered in as a variable. The database I was taking the values from wasn't configured properly. In short, when entering data into AD you need to make sure you cover all the variables correctly. In my case, the username I was trying to enter, was too long.
"Test User" actually was being entered as "Test User ". With all the spaces in there I couldn't figure out what was going on. Tried different methods of changing the output and finally went back to the database. It wasn't getting entered in as text right, no matter what the entry was the text coming out was the full 30 characters alloted long. Fixed that, code worked right away.
djalbert djalbertPosted Jul 17, 2008, 9:48 AM