我需要使用c#将Active Directory用户的密码从一个域更改为其他域 [英] I need to change password of Active Directory Users from one domain to other domain using c#

查看:64
本文介绍了我需要使用c#将Active Directory用户的密码从一个域更改为其他域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我更改现有域的密码时,给定的代码工作正常但是当我尝试更改其他域的密码时,我得到异常已被调用目标抛出错误。



public void ChangePassword(string userDn,string oldpassword,string newpassword)

{

DirectoryEntry user = new DirectoryEntry(userDn);

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

user.Close();

}

When I change password of existing domain the given code is working fine but when I'll try to change password of other domain, I get "Exception has been thrown by the target of an invocation" error.

public void ChangePassword(string userDn, string oldpassword, string newpassword)
{
DirectoryEntry user = new DirectoryEntry(userDn);
user.Invoke("ChangePassword", new object[] { oldpassword, newpassword });
user.Close();
}

推荐答案

好吧,既然你没有将凭证传递给DirectoryEntry构造函数,那么运行程序的安全上下文(Principal)需要对目标有一些管理权限域。这意味着您需要建立域信任,并且上下文帐户需要属于具有管理员权限的组(在目标域上)。



或者,通过构造函数重载传递管理员凭据:

https://msdn.microsoft.com/en-us/library/bw8k1as4(v = vs.110).aspx
Well, since you're not passing credentials to the DirectoryEntry constructor the security context (Principal) that the program is running in would need some administrative rights on the target domain. That means that you would need to have a domain trust established, and the context account would need to belong to a group (on the target domain) that has admin rights.

Alternatively, pass admin credentials via the constructor overloads:
https://msdn.microsoft.com/en-us/library/bw8k1as4(v=vs.110).aspx


这篇关于我需要使用c#将Active Directory用户的密码从一个域更改为其他域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆