Click here to Skip to main content
13,046,773 members (42,349 online)
Rate this:
Please Sign up or sign in to vote.
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 });

Please help me :)
Posted 10-Feb-12 8:46am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Amir Sacic 15-Feb-12 8:37am
Hi !
Yes you were right, I had to start my application as Administrator to change the password.

how simple some solutions are :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 10 Feb 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100