Click here to Skip to main content
15,311,014 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I change password of existing domain the given code is working fine but when I'll try to change password of other domain, I get "Exception has been thrown by the target of an invocation" error.

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

1 solution

Well, since you're not passing credentials to the DirectoryEntry constructor the security context (Principal) that the program is running in would need some administrative rights on the target domain. That means that you would need to have a domain trust established, and the context account would need to belong to a group (on the target domain) that has admin rights.

Alternatively, pass admin credentials via the constructor overloads:
https://msdn.microsoft.com/en-us/library/bw8k1as4(v=vs.110).aspx
   

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