Condividi tramite


Metodo IInitiateWinSATAssessment::InitiateFormalAssessment (winsatcominterfacei.h)

[IInitiateWinSATAssessment::InitiateFormalAssessment può essere modificato o non disponibile per le versioni dopo Windows 8.1.]

Avvia una valutazione formale.

Sintassi

HRESULT InitiateFormalAssessment(
  [in, optional] IWinSATInitiateEvents *pCallbacks,
  [in, optional] HWND                  callerHwnd
);

Parametri

[in, optional] pCallbacks

Interfaccia IWinSATInitiateEvents implementata per ricevere una notifica al termine o al completamento della valutazione. Può essere NULL se non si desidera ricevere notifiche.

[in, optional] callerHwnd

Handle della finestra del client. L'handle viene usato per centrare le finestre di dialogo di WinSAT. Se NULL, le finestre di dialogo sono centrate sul desktop.

Valore restituito

Questo metodo può restituire uno di questi valori.

Nella tabella seguente sono elencati alcuni dei valori HRESULT restituiti da questo metodo.

Codice/valore restituito Descrizione
S_OK
WinSAT avviato correttamente. Per determinare se la valutazione è stata eseguita correttamente, implementare il metodo IWinSATInitiateEvents::WinSATComplete e controllare il valore del parametro hresult .
WINSAT_ERROR_WINSAT_DOES_NOT_EXIST
0x80040011
Impossibile trovare il programma WinSAT dove previsto.

Commenti

In genere si esegue una valutazione formale per valutare tutti i sottocomponenti del computer, mentre una valutazione ad hoc valuta un sottocomponente del computer. Per eseguire una valutazione ad hoc, chiamare il metodo IInitiateWinSATAssessment::InitiateAssessment .

Per ottenere i risultati di una valutazione formale, usare l'interfaccia IQueryRecentWinSATAssessment .

Se si chiama questa funzione da un'applicazione Windows, implementare l'interfaccia IWinSATInitiateEvents in modo che sia possibile visualizzare le informazioni sullo stato di avanzamento e ricevere una notifica al termine della valutazione. Per un'applicazione console di Windows, la visualizzazione dello stato di avanzamento non è necessaria perché WinSAT scrive le informazioni sullo stato di avanzamento nella finestra della console.

Si noti che WinSAT richiede privilegi di amministratore per l'esecuzione. Se l'utente non dispone di privilegi di amministratore, WinSAT visualizzerà una finestra di dialogo che richiede le credenziali.

Esempio

Nell'esempio seguente viene illustrato come eseguire una valutazione formale e ricevere una notifica dello stato di avanzamento.

#include <windows.h>
#include <stdio.h>
#include <conio.h>  // For kbhit()
#include <winsatcominterfacei.h>

#pragma comment(lib, "ole32.lib")

// Class that implements IWinSATInitiateEvents. Implement this class to
// get progress information and completion notification.
class CWinSATCallbacks : public IWinSATInitiateEvents
{
    LONG m_lRefCount;

public:

    // Constructor, Destructor
    CWinSATCallbacks() {m_lRefCount = 1;};
    ~CWinSATCallbacks() {};

    // IUnknown methods
    HRESULT __stdcall QueryInterface(REFIID riid, LPVOID *ppvObj);
    ULONG __stdcall AddRef();
    ULONG __stdcall Release();

    // IWinSATInitiateEvents methods
    HRESULT __stdcall WinSATComplete(HRESULT hr, LPCWSTR description);
    HRESULT __stdcall WinSATUpdate(UINT currentTick, UINT tickTotal, LPCWSTR currentState);
};


HRESULT CWinSATCallbacks::QueryInterface(REFIID riid, LPVOID* ppvObj) 
{
    if (riid == __uuidof(IUnknown) || riid == __uuidof(IWinSATInitiateEvents)) 
    {
        *ppvObj = this;
    }
    else
    {
        *ppvObj = NULL;
        return E_NOINTERFACE;
    }

    AddRef();
    return NOERROR;
}

ULONG CWinSATCallbacks::AddRef() 
{
    return InterlockedIncrement(&m_lRefCount);
}

ULONG CWinSATCallbacks::Release() 
{
    ULONG  ulCount = InterlockedDecrement(&m_lRefCount);

    if(0 == ulCount) 
    {
        delete this;
    }

    return ulCount;
}

// Is called when WinSAT completes the assessment or an error occurs.
HRESULT CWinSATCallbacks::WinSATComplete(HRESULT hr, LPCWSTR description)
{
    if (SUCCEEDED(hr))
    {
        wprintf(L"\n*** %s", description);
    }
    else
    {
        wprintf(L"\n*** The assessment failed with 0x%x (%s)\n", hr, description);
    }

    return S_OK;
}

// Is called when the assessment makes progress. Indicates the percentage of the assessment
// that is complete and the current component being assessed.
HRESULT CWinSATCallbacks::WinSATUpdate(UINT currentTick, UINT tickTotal, LPCWSTR currentState)
{
    // Typically, you would provide the tick values to a ProgressBar control.

    if (tickTotal > 0)
    {
        wprintf(L"\n*** Percent complete: %u%%\n", 100*currentTick/tickTotal);
        wprintf(L"*** Currently assessing: %s\n\n", currentState);
    }

    return S_OK;
}

void main(void)
{
    HRESULT hr = S_OK;
    IInitiateWinSATAssessment* pAssessment = NULL;
    CWinSATCallbacks* pCallbacks = NULL;  // Class that implements IWinSATInitiateEvents

    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

    // Get an instance of the assessment interface.
    hr = CoCreateInstance(__uuidof(CInitiateWinSAT),
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          __uuidof(IInitiateWinSATAssessment),
                          (void**)&pAssessment);

    if (FAILED(hr))
    {
        wprintf(L"Failed to create an instance of IInitiateWinSATAssessment. Failed with 0x%x.\n", hr);
        goto cleanup;
    }

    wprintf(L"Running formal assessment... hit any key when complete.\n");

    pCallbacks = new CWinSATCallbacks();
    if (NULL == pCallbacks)
    {
        wprintf(L"Failed to create an instance of the CWinSATCallbacks class.\n");
        goto cleanup;
    }

    // Run the formal assessment.
    hr = pAssessment->InitiateFormalAssessment(pCallbacks, NULL);
    if (FAILED(hr))
    {
        // This is a failure to start WinSAT. If WinSAT fails while running, 
        // your implementation of the IWinSATInitiateEvents::WinSATComplete 
        // method will receive the failure code.
        wprintf(L"InitiateFormalAssessment failed with 0x%x.\n", hr);
        goto cleanup;
    }

    while (!_kbhit())
        Sleep(10);

cleanup:

    if (pAssessment)
        pAssessment->Release();

    if (pCallbacks)
        pCallbacks->Release();

    CoUninitialize();
}

Requisiti

   
Client minimo supportato Windows Vista [solo app desktop]
Server minimo supportato Nessuno supportato
Piattaforma di destinazione Windows
Intestazione winsatcominterfacei.h
DLL Winsatapi.dll

Vedi anche

IInitiateWinSATAssessment

IInitiateWinSATAssessment::InitiateAssessment

IQueryRecentWinSATAssessment