Directory Services

IADsUser::ChangePassword

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

HRESULT ChangePassword( 
  BSTR bstrOldPassword,
  BSTR bstrNewPassword
);

Parameters

bstrOldPassword
[in] The current password.
bstrNewPassword
[out] The new password.

Return Values

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

Remarks

The method used to change the password is provider-specific. The system LDAP provider initially attempts a LDAP change password operation, if a secure SSL connection to the server is established. If this attempt fails, the LDAP provider then calls the Active Directory specific network management API, NetUserChangePassword.

Example Code [Visual Basic]

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

Example Code [C++]

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

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

Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Iads.h.

See Also

IADsUser, IADsUser Property Methods, ADSI Error Codes