Metodo IInitiateWinSATAssessment::InitiateAssessment (winsatcominterfacei.h)
[IInitiateWinSATAssessment::InitiateAssessment può essere modificato o non disponibile per le versioni dopo Windows 8.1.]
Avvia una valutazione ad hoc.
Sintassi
HRESULT InitiateAssessment(
[in] LPCWSTR cmdLine,
[in, optional] IWinSATInitiateEvents *pCallbacks,
[in, optional] HWND callerHwnd
);
Parametri
[in] cmdLine
Argomenti della riga di comando da passare a WinSAT. La riga di comando non può essere vuota. Per l'utilizzo della riga di comando, vedere Informazioni di riferimento sui comandi winSAT in Microsoft TechNet.
[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 |
---|---|
|
WinSAT avviato correttamente. Per determinare se la valutazione è stata eseguita correttamente, implementare il metodo IWinSATInitiateEvents::WinSATComplete e controllare il valore del parametro hresult . |
|
La riga di comando non può essere vuota; è necessario specificare gli argomenti della riga di comando. |
|
La riga di comando è troppo lunga. La lunghezza massima è di 30.720 byte. |
|
Impossibile trovare il programma WinSAT dove previsto. |
Commenti
In genere si esegue una valutazione ad hoc per valutare un sottocomponente del computer, mentre una valutazione formale valuta tutti i sottocomponenti del computer. Per eseguire una valutazione formale, chiamare il metodo IInitiateWinSATAssessment::InitiateFormalAssessment .
Le valutazioni ad hoc non vengono salvate nell'archivio dati WinSAT; solo le valutazioni formali vengono salvate nell'archivio dati (non è possibile usare l'interfaccia IQueryRecentWinSATAssessment per eseguire query sui risultati). Per ottenere i risultati di una valutazione ad hoc, includere l'argomento –xml FileName , che salverà i risultati in un file XML che sarà possibile analizzare in un secondo momento.
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 ad hoc 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")
BOOL IsKeyEvent(HANDLE hStdIn);
// 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;
}
// There is no progress information for ad hoc assessment. The method provides the
// name of the component being assessed.
HRESULT CWinSATCallbacks::WinSATUpdate(UINT currentTick, UINT tickTotal, LPCWSTR currentState)
{
return S_OK;
}
void main(void)
{
HRESULT hr = S_OK;
IInitiateWinSATAssessment* pAssessment = NULL;
CWinSATCallbacks* pCallbacks = NULL; // Class that implements IWinSATInitiateEvents
LPWSTR pCommand = L"mem -buffersize 32MB -xml .\\MemoryAssessment.xml";
HANDLE hConsole = INVALID_HANDLE_VALUE;
DWORD dwWait = 0;
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");
// Get a handle for console input, so you can break out of the loop.
hConsole = GetStdHandle(STD_INPUT_HANDLE);
if (INVALID_HANDLE_VALUE == hConsole)
{
wprintf(L"GetStdHandle failed with %lu.\n", GetLastError());
goto cleanup;
}
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->InitiateAssessment(pCommand, 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;
}
// Loop until the user presses a key or there is an error.
while (true)
{
dwWait = WaitForSingleObject(hConsole, INFINITE);
if (WAIT_OBJECT_0 == dwWait) // Console input
{
if (IsKeyEvent(hConsole))
break;
}
else if (WAIT_FAILED == dwWait)
{
wprintf(L"WaitForSingleObject failed with %lu\n", GetLastError());
break;
}
}
cleanup:
if (pAssessment)
pAssessment->Release();
if (pCallbacks)
pCallbacks->Release();
if (hConsole)
CloseHandle(hConsole);
CoUninitialize();
}
// Determines whether the console input was a key event.
BOOL IsKeyEvent(HANDLE hStdIn)
{
INPUT_RECORD Record[128];
DWORD dwRecordsRead = 0;
BOOL fKeyPress = FALSE;
if (ReadConsoleInput(hStdIn, Record, 128, &dwRecordsRead))
{
for (DWORD i = 0; i < dwRecordsRead; i++)
{
if (KEY_EVENT == Record[i].EventType)
{
fKeyPress = TRUE;
break;
}
}
}
return fKeyPress;
}
Requisiti
Client minimo supportato | Windows Vista [solo app desktop] |
Server minimo supportato | Nessuno supportato |
Piattaforma di destinazione | Windows |
Intestazione | winsatcominterfacei.h |
DLL | Winsatapi.dll |