Platform SDK: Active Directory, ADSI, and Directory Services

IADsUser::ChangePassword

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

HRESULT IADsUser::ChangePassword(
  BSTR bstrOldPassword,  
  BSTR bstrNewPassword    
);

Parameters

bstrOldPassword
[in] The password as it currently exists.
bstrNewPassword
[out] The new password to use.

Return Values

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

Example Code [Visual Basic]

The following Visual Basic code snippet shows how to change the password of a user.

Dim usr As IADsUser
Set usr = GetObject("WinNT://Microsoft/JSmith,user")
usr.ChangePassword "guesswhat?", "topsecret98"

Example Code [C++]

The following C++ code snippet 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 from %S to %S\n",
                          oldPasswd, newPasswd);
     return hr;
}

HRESULT GetUserObject(LPWSTR); // function listed elsewhere in 
                               // IADsUser Property Methods.

int main(int argc, char* argv[])
{
    HRESULT hr = CoInitialize(NULL);
    IADsUser *pUser = GetUserObject( 
                      L"WinNT://Microsoft/JSmith,user");
    pUser-AddRef();
    hr = ChangePassword(pUser, L"guessWhat", L"tOpSecrete98");
    if(pUser) pUser->Release();
    CoUninitialize();
    return 0;
}

Requirements

  Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with DSClient).
  Windows 95/98: Requires Windows 95 or later (with DSClient).
  Header: Declared in Iads.h.

See Also

IADsUser, IADsUser Property Methods, ADSI Error Codes