在Microsoft Active Directory(AD)中,如果有人密码过期,如何使用旧密码更改密码 。
我知道System.DirectoryService
有一个ChangePassword
方法,但在密码过期时无效。
我非常想要一些帮助!
BTW,无法使用SetPassword
方法,因为它必须具有特殊权限。
答案 0 :(得分:1)
您可以使用netapi32.dll中的NetUserChangePassword功能。
[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
);