DirectoryEntryObject.Invoke("ChangePassword", new object[] { oldPassword, newPassword } );
throws the following error:
"System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.Runtime.InteropServices.COMException (0x80020005): Type mismatch.
(Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
--- End of inner exception stack trace ---
at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)
Is this something to do with any settings in the AD or I am missing anything?
There's an MSDN page titled Managing User Passwords that has some examples of how to call ChangePassword
from C#. The specific sample shows the following syntax:
usr.Invoke("ChangePassword", OldSecurelyStoredPassword, NewSecurelyStoredPassword);
I suspect it's because you're calling it and passing in an object array, rather than passing two strings explicitly (the documentation you've linked to in your comment indicates that it expects to be passed two strings, one as an input parameter and one as an output parameter. Try this:
var oldPassword = "TheOldPassword";
var newPassword = "TheNewPassword";
DirectoryEntryObject.Invoke("ChangePassword", oldPassword, newPassword);
User contributions licensed under CC BY-SA 3.0