Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# User-controls LDAP
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 Smile | :)
Posted 10-Feb-12 9:46am

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
Amir Sacic at 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
0 Sergey Alexandrovich Kryukov 334
1 Kornfeld Eliyahu Peter 325
2 Maciej Los 239
3 OriginalGriff 188
4 King Fisher 185
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 10 Feb 2012
Copyright © CodeProject, 1999-2014
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