小编Car*_*mpo的帖子

使用.NET在sAMAccountName中创建具有超过20个字符的用户时出错

我正在尝试以编程方式创建一个新的Active Directory用户,使用大于20个字符的值设置sAMAccountName属性.

当我调用DirectoryEntry.CommitChanges()时,我收到错误:

00000523:SysErr:DSID-031A0FB6,问题22(参数无效),数据0

如果我尝试创建一个新用户设置sAMAccountName小于20个字符,一切正常.

在有人说sAMAccountName的限制为20个字符之前,我想指出,如果我尝试使用Windows工具"Active Directory用户和计算机"创建具有超过20个字符的sAMAccountName的同一用户,一切正常.我可以使用LDP工具在AD中看到新条目,并且条目具有超过20个字符的sAMAccountName.

为什么我不能使用.NET以编程方式创建用户?

以下是我正在使用的代码:

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
Run Code Online (Sandbox Code Playgroud)

.net c# vb.net active-directory

9
推荐指数
1
解决办法
6686
查看次数

标签 统计

.net ×1

active-directory ×1

c# ×1

vb.net ×1