首页 > 解决方案 > 如何使用 C# 在 Exchange 中重置密码

问题描述

我无法从 C# 重置活动目录密码,我有这个代码

DirectoryEntry de = new DirectoryEntry(path, dominio + @"\" + usu, pass1, AuthenticationTypes.Secure);
DirectorySearcher ds = new DirectorySearcher(de);
try
{
    string strFilter = "(&(objectClass=user)(|(sAMAccountName="+nameid+")))";
    ds.Filter = strFilter;
    ds.PropertiesToLoad.Add("displayName");
    ds.PropertiesToLoad.Add("sAMAccountName");
    ds.PropertiesToLoad.Add("DistinguishedName");
    ds.PropertiesToLoad.Add("CN");
    SearchResult result = ds.FindOne();
    string dn = result.Properties["DistinguishedName"][0].ToString();

    var user = result.GetDirectoryEntry();
    user.Invoke("ChangePassword", new object[] { oldpassword, newpassword });
    user.CommitChanges();

    MessageBox.Show("ok");
}
catch(Exception ex)
{
    MessageBox.Show("error");
}

它工作正常,直到 INVOKE 行,那是我收到错误的时候

user.Invoke("ChangePassword", new object[] { oldpassword, newpassword });

标签: c#exchange-server

解决方案


推荐阅读