| Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsUser::ChangePassword method changes the user password from the specified old value to a new value.
HRESULT IADsUser::ChangePassword( BSTR bstrOldPassword, BSTR bstrNewPassword );
This method supports the standard return values, including S_OK. For other return values, see ADSI Error Codes.
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"
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;
}
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.