Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsUser::SetPassword method sets the user password to a specified value. The user account must have been created and stored in the underlying directory using IADs::SetInfo before IADsUser::SetPassword is called.
HRESULT IADsUser::SetPassword( BSTR bstrNewPassword );
This method supports the standard return values, including S_OK. For other return values, see ADSI Error Codes.
In Active Directory IADsUser::SetPassword uses the Kerberos protocol when you call this method on a user object in the same directory forest. For this to work properly, you should bind to the user object using either a serverless ADsPath, such as "LDAP://CN=Jane Smith, CN=sales, DC=Microsoft, DC=com" or a server-explicit ADsPath with a DNS server name, such as "LDAP://server1.Microsoft.com/CN=jane smith, CN=Sales, DC=Microsoft, DC=com".
The following Visual Basic code snippet illustrates how to set the user password, assuming you have the permission to do so.
Dim usr As IADsUser Set usr = GetObject("WinNT://Microsoft/JSmith,user") usr.SetPassword "topsecret98"
The following C++ code snippet shows how to set the user password, assuming you have the permission.
HRESULT SetPassword(IADsUser *pUser, LPWSTR passwd) { HRESULT hr=S_OK; if(!pUser) { return E_FAIL;} hr = pUser->SetPassword(passwd); if (hr == S_OK) printf("User password has been setn"); pUser->Release(); 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 = SetPassword(pUser, 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.
IADsMembers, IADsUser, IADsUser Property Methods, IADs::SetInfo, ADSI Error Codes, IADsServiceOperations