IADsUser::ChangePassword method

In this article

The IADsUser::ChangePassword method changes the user password from the specified old value to a new value.

Syntax

HRESULT ChangePassword(
BSTR bstrOldPassword,
BSTR bstrNewPassword
);

Parameters

bstrOldPassword

A BSTR that contains the current password.

bstrNewPassword

A BSTR that contains the new password.

Return Value

This method supports the standard return values, including S_OK. For more information and other return values, see ADSI Error Codes.

Remarks

IADsUser::ChangePassword functions similarly to IADsUser::SetPassword in that it will use one of three methods to try to change the password. Initially, the LDAP provider will attempt an LDAP change password operation, if a secure SSL connection to the server is established. If this attempt fails, the LDAP provider will next try to use Kerberos (see IADsUser::SetPassword for some problems that may result on Windows with cross-forest authentication), and if this also fails, it will finally call the Active Directory specific network management API, NetUserChangePassword.

In Active Directory, the caller must have the Change Password extended control access right to change the password with this method.

Examples

The following code example shows how to change a user password.

Dim usr As IADsUser
Dim szOldPass As String
Dim szNewPass As String
On Error GoTo Cleanup
Set usr = GetObject("WinNT://Fabrikam/JeffSmith,user")
' Add code to securely retrieve the old and new password.
usr.ChangePassword szOldPass, szNewPass
Cleanup:
If (Err.Number<>0) Then
MsgBox("An error has occurred. " & Err.Number)
End If
Set usr = Nothing