IInitiateWinSATAssessment::InitiateFormalAssessment 方法 (winsatcominterfacei.h)
[IInitiateWinSATAssessment::InitiateFormalAssessment 可能会在Windows 8.1后更改或不可用。]
启动正式评估。
语法
HRESULT InitiateFormalAssessment(
[in, optional] IWinSATInitiateEvents *pCallbacks,
[in, optional] HWND callerHwnd
);
参数
[in, optional] pCallbacks
实现的 IWinSATInitiateEvents 接口,用于在评估完成或取得进展时接收通知。 如果不想接收通知,可以为 NULL 。
[in, optional] callerHwnd
客户端的窗口句柄。 句柄用于居中 WinSAT 对话框。 如果 为 NULL,则对话框在桌面上居中。
返回值
此方法可以返回其中一个值。
下表列出了此方法返回的一些 HRESULT 值。
返回代码/值 | 说明 |
---|---|
|
WinSAT 已成功启动。 若要确定评估是否成功运行,请实现 IWinSATInitiateEvents::WinSATComplete 方法并检查 hresult 参数的值。 |
|
找不到预期位置的 WinSAT 程序。 |
注解
通常运行正式评估来评估计算机的所有子组件,而临时评估会评估计算机的一个子组件。 若要运行临时评估,请调用 IInitiateWinSATAssessment::InitiateAssessment 方法。
若要获取正式评估的结果,请使用 IQueryRecentWinSATAssessment 接口。
如果从 Windows 应用程序调用此函数,请实现 IWinSATInitiateEvents 接口,以便在评估完成后显示进度信息并接收通知。 对于 Windows 控制台应用程序,不需要显示进度,因为 WinSAT 会将进度信息写入控制台窗口。
请注意,WinSAT 需要管理员权限才能运行。 如果用户没有管理员权限,WinSAT 将显示一个要求提供凭据的对话框。
示例
以下示例演示如何运行正式评估并接收有关其进度的通知。
#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();
}
要求
最低受支持的客户端 | Windows Vista [仅限桌面应用] |
最低受支持的服务器 | 无受支持的版本 |
目标平台 | Windows |
标头 | winsatcominterfacei.h |
DLL | Winsatapi.dll |