IADsServiceOperations::SetPassword method

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.

Syntax

HRESULT SetPassword(
  BSTR bstrNewPassword
);

Parameters

bstrNewPassword

The null-terminated Unicode string to be stored as the new password.

Return Value

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

Remarks

The property IADsService::get_ServiceAccountName identifies the account for which this password is to be set.

Examples

The following code example shows how to set a password for the Microsoft Fax Service running on Windows 2000.

VB
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.
C++
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**)&amp;pCont);
if(FAILED(hr)) 
{
    goto Cleanup;
}

hr = pCont-&gt;GetObject(CComBSTR("Service"), CComBSTR("Fax"), &amp;pDisp);
if(FAILED(hr)) 
{
    goto Cleanup;
}

hr = pDisp-&gt;QueryInterface(IID_IADsServiceOperations, (void**)&amp;pSrvOp);
if(FAILED(hr)) 
{
    goto Cleanup;
}

// Insert code to securely retrieve the password from the user.
hr = pSrvOp-&gt;SetPassword(CComBSTR(pwszPassword));

Cleanup: if(pDisp) { pDisp->Release(); } if(pCont) { pCont->Release(); } if(pSrvOp) { pSrvOp->Release(); } }

Requirements

   
Windows version Windows Vista Windows Server 2008
Target Platform Windows
Header iads.h
DLL Activeds.dll

See Also

IADsService

IADsService::get_ServiceAccountName

IADsServiceOperations