由网友(弃梦人)分享简介:我试图创建使用以下code段的新用户。 I'm attempting to create a new user using the following code snippet. using (var ad = new PrincipalContext(ContextType.Domain, "",...
我试图创建使用以下code段的新用户。
I'm attempting to create a new user using the following code snippet.
using (var ad =
new PrincipalContext(ContextType.Domain,
"<domain>",
"<ad user>",
"<ad pass>"))
{
using (var aduser = new UserPrincipal(ad, "dummy", "password", false))
{
aduser.Save();
}
}
不过,我得到的消息 RPC无法
与 0x800706BA
错误code。
有没有人见过吗?
和,更importat,解决了这个问题!
And, more importat, solved it!
推荐答案
尽管通过.NET 3.5中提供的AccountManagement接口,用于我的问题没有工作,回落至忠实LDAP工作。所以我在这里张贴后人。
Although the AccountManagement interfaces provided by .NET 3.5 didn't work for my issue, falling back to the faithful LDAP worked. So I'm posting here to posterity.
/*
* First we need to create the user...
*/
using (var dirEntry = new DirectoryEntry("LDAP://<IP/name>",
"<admin>",
"<admin pass>",
AuthenticationTypes.ServerBind))
{
using (var newUser = dirEntry.Children.Add("CN=dummy", "user"))
{
newUser.Properties["samAccountName"].Value = "dummy";
newUser.CommitChanges();
}
}
/*
* Then set its password!
*
* If the password is set in the same
* transaction as the creation an error occurr.
*/
using (var user = new DirectoryEntry("LDAP://<IP/name>/CN=dummy,DC=corp",
"<admin>",
"<admin pass>"))
{
user.Invoke("SetPassword", new object[] { "password" });
user.CommitChanges();
}
相关推荐
最新文章