IADsUser::ChangePassword method

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.

VB
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

The following code example shows how to change a user password.
C++
HRESULT ChangePassword(
    IADsUser *pUser, 
    LPWSTR oldPasswd, 
    LPWSTR newPasswd)
{
    HRESULT hr=S_OK;
    if(!pUser) { return E_FAIL;}
    hr = pUser->ChangePassword(oldPasswd, newPasswd);
    printf("User password has been changed");
    return hr;
}

Requirements

   
Minimum supported client Windows Vista
Minimum supported server Windows Server 2008
Target Platform Windows
Header iads.h
DLL Activeds.dll

See Also

ADSI Error Codes

IADsUser

IADsUser Property Methods