Note that there are some explanatory texts on larger screens.

plurals
  1. POError creating a user with more than 20 chars in sAMAccountName using .NET
    primarykey
    data
    text
    <p>I'm trying to programatically create a new Active Directory user setting the sAMAccountName attribute with a value larger than 20 chars.</p> <p>When I call the DirectoryEntry.CommitChanges(), I get the error:</p> <blockquote> <p>00000523: SysErr: DSID-031A0FB6, problem 22 (Invalid argument), data 0</p> </blockquote> <p>If I try to create a new user setting the sAMAccountName smaller than 20 chars everything work.</p> <p>Before someone says the the limit of the sAMAccountName is 20 chars, I want to point out that if I try to create the same user having the sAMAccountName more than 20 chars using the Windows tool "Active Directory Users and Computers" everything works. I can see the new entry in AD using the LDP tool and the entry has the sAMAccountName with more than 20 chars.</p> <p>Why can't I create the user programatically using .NET?</p> <p>Below is the code I'm using:</p> <pre><code>Using objDirEnt As DirectoryEntry = New DirectoryEntry("LDAP://my.domain.com/cn=Users,dc=my,dc=domain,dc=com", "username", "Password", AuthenticationTypes.Secure Or AuthenticationTypes.Sealing) Using usuario As DirectoryEntry = objDirEnt.Children.Add("CN=aaaaaa bbbbbbbbbb ccccccccc (aaaaaa.bbbbbb.ccccccccc)", "user") usuario.Properties("sAMAccountName").Value = "aaaaaa.bbbbbb.ccccccccc" usuario.Properties("userAccountControl").Value = AdsUserFlags.PasswordNotRequired usuario.Properties("name").Value = "aaaaaa bbbbbbbbbb ccccccccc" usuario.Properties("givenName").Value = "aaaaaa" usuario.Properties("sn").Value = "bbbbbbbbbb ccccccccc" usuario.CommitChanges() End Using End Using </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload