通过C#更改Active Directory用户的密码 [英] Change Passwords of Active Directory Users via C#

查看:165
本文介绍了通过C#更改Active Directory用户的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我只想问你一个简单的问题.

如何在Active Directory中更改用户密码...
每次尝试更改时,都会收到一个COM-Exception Unkown错误

Hello !

I just want to ask you a quick question.

How to change userpasswords in Active Directory ...
Every time i''ll try to change, i get a COM-Exception Unkown error

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



请帮助我:)



Please help me :)

推荐答案

阿米尔,

如果在AD中更改用户密码,则应确保您具有执行该操作的足够权限.在复杂的AD部署中(如在公司环境中),更改密码的权限由域管理员拥有,因此您拥有成为域管理员或托管该域的系统的管理员.

您也可以使用WIN32 API更改密码

您可以使用win32 api的 NetUserChangePassword 更改密码.根据我的经验,我发现DirectoryEntry并不总是有效.

如果您认为这不能解决您的问题,请获取COM异常,我们可以尝试找出问题所在.
Hi Amir,

I case of changing the password of a user in the AD you should make sure that you have sufficient rights to perform the operation.In a complex AD deployment as in a corporate environment the right to change password resides with the domain administrator,so you have to be either a domain administrator or the administrator of the system on which the domain is hosted.

Also you can use the WIN32 API to change the password

you can use NetUserChangePassword of the win32 api to change the password.From my experience I found that DirectoryEntry will not always work.

If you feel this does not answer your question,get the COM exception we can try and find out the problem.


这篇关于通过C#更改Active Directory用户的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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