共用方式為


IADsServiceOperations::SetPassword 方法 (iads.h)

IADsServiceOperations::SetPassword 方法會設定服務管理員所使用的帳戶密碼。 建立此服務的安全性內容時,會呼叫這個方法。

語法

HRESULT SetPassword(
  [in] BSTR bstrNewPassword
);

參數

[in] bstrNewPassword

要儲存為新密碼的 Null 終止 Unicode 字串。

傳回值

這個方法支持標準傳回值,包括S_OK。 如需其他傳回值的詳細資訊,請參閱 ADSI 錯誤碼

備註

屬性 IADsService::get_ServiceAccountName會識別要設定此密碼的帳戶。

範例

下列程式代碼範例示範如何為在 Windows 2000 上執行的 Microsoft 傳真服務設定密碼。

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

下列程式代碼範例示範如何為在 Windows 2000 上執行的 Microsoft 傳真服務設定密碼。

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();
    }
}

規格需求

需求
最低支援的用戶端 Windows Vista
最低支援的伺服器 Windows Server 2008
目標平台 Windows
標頭 iads.h
Dll Activeds.dll

另請參閱

IADsService

IADsService::get_ServiceAccountName

IADsServiceOperations