前面说过的更改密码方法,都时灵时不灵,没辙了,现在用dotnet中提供的DirectoryServices来实现.(C#风格,注意在前面using一下System.DirectoryServices)
private void setpassButton_Click(object sender, EventArgs e)
{
DirectoryEntry admin = new DirectoryEntry("LDAP://zhang-yunfeng.zyf.com/" + TextBoxUser.Text.Trim());
try
{
admin.Invoke("SetPassword", new object[] {passwordBox.Text.Trim() });
admin.CommitChanges();
admin.Close();
MessageBox.Show("新密码为:" + passwordBox.Text.Trim());
}
catch (Exception ex)
{
MessageBox.Show("Error setting password: " + ex.ToString());
return;
}
finally
{
admin.Dispose();
}
}