1

你好如何从这个数组中获取数据?或者如何获取我可以提取的所有名称?

hres = pSvc->ExecNotificationQueryAsync( _bstr_t("WQL"), _bstr_t("SELECT * " 
            "FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'"), 
        WBEM_FLAG_SEND_STATUS,  NULL, pStubSink);
for (int i = 0; i < lObjectCount; i++)
{
    VARIANT varName;
    hres = apObjArray[i]->Get(_bstr_t(L"__CLASS"),
        0, &varName, 0, 0);

    if (FAILED(hres))
    {
        cout << "Failed to get the data from the query"
            << " Error code = 0x"
            << hex << hres << endl;
        return WBEM_E_FAILED;       // Program has failed.
    }

    printf("Name: %ls\n", V_BSTR(&varName));
}
4

1 回答 1

1

您的代码不起作用,因为ExecNotificationQueryAsync方法的结果必须使用 IWbemObjectSink对象进行处理。试试这个 MSDN 示例Receiving Event Notifications Through WMI您还可以使用WMI Delphi Code Creator生成 C++ 代码之类的工具来访问 WMI。

于 2013-05-01T16:42:44.550 回答