C# 如何在与C交换时重置密码#

C# 如何在与C交换时重置密码#,c#,exchange-server,C#,Exchange Server,我无法从C#重置active directory密码,我有以下代码 DirectoryEntry de = new DirectoryEntry(path, dominio + @"\" + usu, pass1, AuthenticationTypes.Secure); DirectorySearcher ds = new DirectorySearcher(de); try { string strFilter = "(&(objectClass

我无法从C#重置active directory密码,我有以下代码

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");
}
它工作正常,直到调用行,这时我得到一个错误

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

您可以添加收到的错误消息吗?英文版:“调用目标发生异常。”“这是否回答了您的问题?我怀疑这是一个权限问题,就像建议的副本一样。您好,朋友们,我能够解决这个问题,windows server 2003不允许调用,迁移到windows server 2012,并且使用相同的代码,它可以完美地工作。谢谢大家