Directory Services |
The IADsServiceOperations::SetPassword method sets the password for the account used by the service manager. This method is called when the security context for this service is created.
HRESULT SetPassword( BSTR bstrNewPassword );
This method supports the standard return values, including S_OK. For more information about other return values, see ADSI Error Codes.
The property IADsService::get_ServiceAccountName identifies the account for which this password is to be set.
The following code example shows how to set a password for the Microsoft Fax Service running on Windows 2000.
Dim cp As IADsComputer Dim so As IADsServiceOperations Dim s As IADsService Dim sPass As String On Error GoTo Cleanup Set cp = GetObject("WinNT://myMachine,computer") Set so = cp.GetObject("Service", "Fax") ' Insert code to securely retrieve a new password from the user. so.SetPassword sPass Set s = so MsgBox "The password for " & so.name & " has been changed on "_ & s.ServiceAccountName Cleanup: If (Err.Number<>0) Then MsgBox("An error has occurred. " & Err.Number) End If Set cp = Nothing Set so = Nothing Set s = Nothing
The following code example shows how to set a password for the Microsoft Fax Service running on Windows 2000.
HRESULT SetServicePassword(LPCWSTR pwszADsPath, LPCWSTR, pwszPasword) { IADsContainer *pCont = NULL; IADsServiceOperations *pSrvOp = NULL; IDispatch *pDisp = NULL; HRESULT hr = S_OK; hr = ADsGetObject(pwszADsPath, IID_IADsContainer, (void**)&pCont); if(FAILED(hr)) { goto Cleanup; } hr = pCont->GetObject(CComBSTR("Service"), CComBSTR("Fax"), &pDisp); if(FAILED(hr)) { goto Cleanup; } hr = pDisp->QueryInterface(IID_IADsServiceOperations, (void**)&pSrvOp); if(FAILED(hr)) { goto Cleanup; } // Insert code to securely retrieve the password from the user. hr = pSrvOp->SetPassword(CComBSTR(pwszPassword)); Cleanup: if(pDisp) { pDisp->Release(); } if(pCont) { pCont->Release(); } if(pSrvOp) { pSrvOp->Release(); } }
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.
IADsService, IADsService::get_ServiceAccountName, IADsServiceOperations