Metodo IADsServiceOperations::SetPassword (iads.h)
Il metodo IADsServiceOperations::SetPassword imposta la password per l'account usato da Service Manager. Questo metodo viene chiamato quando viene creato il contesto di sicurezza per questo servizio.
Sintassi
HRESULT SetPassword(
[in] BSTR bstrNewPassword
);
Parametri
[in] bstrNewPassword
Stringa Unicode con terminazione null da archiviare come nuova password.
Valore restituito
Questo metodo supporta i valori restituiti standard, inclusi i S_OK. Per altre informazioni sugli altri valori restituiti, vedere Codici di errore ADSI.
Commenti
La proprietà IADsService::get_ServiceAccountName identifica l'account per il quale questa password deve essere impostata.
Esempio
Nell'esempio di codice seguente viene illustrato come impostare una password per il servizio Fax Microsoft in esecuzione in 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
Nell'esempio di codice seguente viene illustrato come impostare una password per il servizio Fax Microsoft in esecuzione in 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();
}
}
Requisiti
Requisito | Valore |
---|---|
Client minimo supportato | Windows Vista |
Server minimo supportato | Windows Server 2008 |
Piattaforma di destinazione | Windows |
Intestazione | iads.h |
DLL | Activeds.dll |