AD and VB.Net

B

Bob

I am having trouble getting some VB.Net code to add a
user to that AD. I'm getting a very odd error that I
can't seem to get rid of and the cause is not making
itself very clear. Not to mention the fact that finding
info on this error is rather tough.

The error I get when try to add the user is:

"An invalid dn syntax has been specified."

It says it is taking place on the line of code in which I
try to set the password for the new user.

Here is my code as it stands now:

Dim de As New DirectoryEntry
("LDAP://CN=Users,DC=thelancaircompany,DC=com", "tlc\admin
istrator", "Password", AuthenticationTypes.Encryption)
Dim user As DirectoryEntry = de.Children.Add
("testa", "user")
Dim pass As New Object()

pass = "NewPassword"

user.Properties("SAMAccountName").Value
= "testa"
user.Properties("userPrincipalName").Value
= "testa"
user.Properties("scriptpath").Value
= "start.bat"
user.Properties("givenname").Value = "test"
user.Properties("sn").Value = "test"
user.Properties("displayname").Value = "test
a. test"
user.Properties("department").Value
= "Accounting"
user.Properties("initials").Value = "A"
user.Properties("profilepath").Value
= "\\condor\files\users\profiles\testa" '& AD1.UserName
user.Invoke("SetPassword", pass)

user.CommitChanges()

Any help would be greatly appreciated.

TIA
 
C

Chriss3 [MVP]

Bob the DN is wrong. with other words the LDAP source are wrong. I give you
an example for the DN to the administrator account

LDAP://CN=Administrator,CN=Users,DC=thelancairccompany,DC=com

More Info:

AD Schema DN Syntax:
http://msdn.microsoft.com/library/d...ry/en-us/adschema/adschema/s_object_ds_dn.asp

Choosing a AS Syntax
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ad/ad/choosing_a_syntax.asp

--
Regards
Christoffer Andersson
Microsoft MVP - Directory Services

No email replies please - reply in the newsgroup
 
G

Guest

Yes, that's what I thought at the beginning too. I don't
want to set the LDAP string to an actual user though as I
am am trying to add a new one. The LDAP sting I have
seems to work just fine in a query when browsing through
objects in the Users connector but when I try to add the
user it gives me that error.
 
C

Chriss3 [MVP]

You need to set the DN attribute as well you set sAMAccountName I guess.

--
Regards
Christoffer Andersson
Microsoft MVP - Directory Services

No email replies please - reply in the newsgroup
 
B

bob

That did it!

Thank you much... :D

-----Original Message-----
You need to set the DN attribute as well you set sAMAccountName I guess.

--
Regards
Christoffer Andersson
Microsoft MVP - Directory Services

No email replies please - reply in the newsgroup
------------------------------------------------
http://www.chrisse.se - Active Directory Tips




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top