gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:49:48 25 4
gpt4 key购买 nike

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

当我调用 DirectoryEntry.CommitChanges() 时,出现错误:

00000523: SysErr: DSID-031A0FB6, problem 22 (Invalid argument), data 0

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

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

为什么我不能使用 .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

最佳答案

根据这篇文章,此字段的默认限制是少于 20 个字符: http://msdn.microsoft.com/en-us/library/ms679635.aspx我没有尝试使用 20 个字符的 sAMAccountName 创建用户,但也许可以使用 Novell LDAP 库。我不得不使用它,因为我们也需要支持其他 LDAP 服务。 http://www.novell.com/coolsolutions/feature/11204.html

我还找到了这些帖子: https://serverfault.com/questions/344815/how-to-add-a-user-in-active-directory-with-name-longer-than-20-characters

关于c# - 使用 .NET 在 sAMAccountName 中创建超过 20 个字符的用户时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9036861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com