Paul Li
Paul Li

Reputation: 23

How to change password in active directory when password expired

In Microsoft Active Directory(AD), if someone password expired, how to change password using their old password.

I know System.DirectoryService has one ChangePassword Method, but it not working when the password expired.

I want some help, than you very much!

BTW, cannot use SetPassword Method, because it have to has special privileges.

Upvotes: 2

Views: 1044

Answers (1)

Ashigore
Ashigore

Reputation: 4678

You can use the NetUserChangePassword function in netapi32.dll.

[DllImport("netapi32.dll", CharSet=CharSet.Unicode,
    CallingConvention=CallingConvention.StdCall,
    SetLastError=true )]
static extern uint NetUserChangePassword (
    [MarshalAs(UnmanagedType.LPWStr)] string domainname,
    [MarshalAs(UnmanagedType.LPWStr)] string username,
    [MarshalAs(UnmanagedType.LPWStr)] string oldpassword,
    [MarshalAs(UnmanagedType.LPWStr)] string newpassword
);

Upvotes: 1

Related Questions