更新时间:2023-08-21 14:28:22
您可以现在就做这整个过程变得更加容易与System.DirectoryServices.AccountManagement(只要你在净3.5):
You can do this whole process much easier now with System.DirectoryServices.AccountManagement (long as you're on .Net 3.5):
这是你的具体情况一个简单的例子:
Here's a quick example of your specific case:
using(var pc = new PrincipalContext(ContextType.Domain))
{
using(var up = new UserPrincipal(pc))
{
up.SamAccountName = username;
up.EmailAddress = email;
up.SetPassword(password);
up.Enabled = true;
up.ExpirePasswordNow();
up.Save();
}
}