Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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


Please help me :)
Posted

1 solution

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.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900