开发者

Weird sAMAccountName when creating user account using DirectoryServices

my C# code uses the DirectoryServices namespace to create domain user accounts.

    DirectoryEntry deRoot = new DirectoryEntry("LDAP://OU=MYOU,DC=DOMAIN,DC=LOCAL");
    directoryEntry = deRoot.Children.Add("CN=Tony", "user");
    directoryEntry.CommitChanges();
    directoryEnt开发者_开发技巧ry.Properties["sAMAccountName"].Value = "Tony1";
    directoryEntry.Properties["displayName"].Value = "Tony Danza";
    directoryEntry.Invoke("SetPassword", "mypass123");
    directoryEntry.CommitChanges();

This successfully creates the account but the sAMAccountName property contains a rather weird value like $HGA000-8FP94NQK9R9I or $NGA000-B3BJ2ELT5OOD. When executed inside my dev-domain, everything's fine.


Try setting the sAMAccountName before the first CommitChanges.

Maybe, since sAMAccountName is a required attribute, the system gives it a default value if you don't provide it when you create the object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜