Click here to Skip to main content
11,721,053 members (81,317 online)
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 8: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 500
1 OriginalGriff 334
2 Mika Wendelius 160
3 F-ES Sitecore 140
4 Maciej Los 80
0 Sergey Alexandrovich Kryukov 2,199
1 OriginalGriff 959
2 F-ES Sitecore 640
3 Maciej Los 609
4 Richard MacCutchan 540


Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 10 Feb 2012
Copyright © CodeProject, 1999-2015
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