Set Username LDAP

G

Guest

Hello together



I have the problem, if I created an user in the AD and I like to rename it,
I can change any properties of the user but in the AD-List there are no
changes. If I like to rename that, I have to right-click on the user an
select "rename". After that, an new window appears with the properties Full
name, First name, Last name, Display name and the user logon names. If I
change the value at "Full name", the name has changed in the overview list in
the AD.

So, my problem is now, to do exactly this with LDAP. Here the code:




1 Private Sub AddADPerson_Do()
2
3 Dim de As New DirectoryEntry(mstrLoginADSConnectionString,
mstrLoginUserID, mstrLoginKennwort)
4 Dim ou As DirectoryEntry = de.Children.Find("CN=Users")
5 Dim dirNewUser As DirectoryEntry = ou.Children.Add("CN=" &
mstrUserID, "User")
6
7
8 If Len(strsamaccountname) > 0 Then
9 Call ADSUserSearchRead()
10 End If
11
12 If bolSearchResultExist = False Then
13 If Len(strsamaccountname) > 0 Then
14 dirNewUser.Properties("sAMAccountname").Value = strsamaccountname
15 dirNewUser.Properties("userPrincipalName").Value =
strsamaccountname & "@" & strDomain & "." & strTopLevelDomain
16 End If
17 If Len(strsn) > 0 Then dirNewUser.Properties("sn").Value = strsn
18 If Len(strgivenname) > 0 Then
dirNewUser.Properties("givenName").Value = strgivenname
19 If Len(strc) > 0 Then dirNewUser.Properties("c").Value = strc
20 If Len(strcompany) > 0 Then
dirNewUser.Properties("Company").Value = strcompany
21 If Len(strl) > 0 Then dirNewUser.Properties("l").Value = strl
22 If Len(strpostalcode) > 0 Then
dirNewUser.Properties("postalCode").Value = strpostalcode
23 If Len(strpostalcode) = 0 Then
dirNewUser.Properties("postalCode").Value = " "
24 If Len(strstreetaddress) > 0 Then
dirNewUser.Properties("streetAddress").Value = strstreetaddress
25 If Len(strmobile) > 0 Then dirNewUser.Properties("mobile").Value
= strmobile
26 If Len(strmobile) = 0 Then dirNewUser.Properties("mobile").Value
= " "
27 If Len(strtelephonenumber) > 0 Then
dirNewUser.Properties("telephonenumber").Value = strtelephonenumber
28 If Len(strtelephonenumber) = 0 Then
dirNewUser.Properties("telephonenumber").Value = " "
29 If Len(strhomephone) > 0 Then
dirNewUser.Properties("homePhone").Value = strhomephone
30 If Len(strhomephone) = 0 Then
dirNewUser.Properties("homePhone").Value = " "
31 If Len(strgivenname) > 0 And Len(strsn) > 0 Then
32 dirNewUser.Properties("displayName").Value = strgivenname & " "
& strsn
33 ElseIf Len(strgivenname) > 0 And Len(strsn) = 0 Then
34 dirNewUser.Properties("displayName").Value = strgivenname
35 ElseIf Len(strgivenname) = 0 And Len(strsn) > 0 Then
36 dirNewUser.Properties("displayName").Value = strsn
37 Else
38 dirNewUser.Properties("displayName").Value = ""
39 End If
40
41 If Len(strgivenname) > 0 And Len(strsn) > 0 Then
dirNewUser.Properties("cn").Value = strgivenname & " " & strsn
42
43 dirNewUser.CommitChanges()
44
45 End If
46
47 End Sub

OIn line 41 I try to change it, but if I do that, the Error "An invalid dn
syntax has been specified. " appears.



Do you know what is wrong?



Thanks, Flubber
 
G

Guest

Dim dirNewUser As DirectoryEntry = ou.Children.Add("CN=" & strgivenname & " "
& strsn, "User")

That was the solution ;)
 

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