27 #include "precompiled.h"
34 #pragma comment(lib, "wbemuuid.lib")
37 static IWbemServices*
pSvc;
52 ENSURE(hr == S_OK || hr == S_FALSE);
60 hr = CoInitializeSecurity(0, -1, 0, 0, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, 0, EOAC_NONE, 0);
65 IWbemLocatorPtr pLoc = 0;
66 hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (
void**)&pLoc);
70 hr = pLoc->ConnectServer(_bstr_t(L
"ROOT\\CIMV2"), 0, 0, 0, 0, 0, 0, &
pSvc);
75 hr = CoSetProxyBlanket(
pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, 0, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, 0, EOAC_NONE);
110 IEnumWbemClassObjectPtr pEnum = 0;
113 HRESULT hr =
pSvc->ExecQuery(L
"WQL", _bstr_t(query), WBEM_FLAG_FORWARD_ONLY|WBEM_FLAG_RETURN_IMMEDIATELY, 0, &pEnum);
120 IWbemClassObjectPtr pObj = 0;
121 ULONG numReturned = 0;
122 hr = pEnum->Next((
LONG)WBEM_INFINITE, 1, &pObj, &numReturned);
130 pObj->BeginEnumeration(WBEM_FLAG_NONSYSTEM_ONLY);
136 if(pObj->Next(0, &name, &value, 0, 0) != WBEM_S_NO_ERROR)
141 instance[name] = value;
144 instances.push_back(instance);
int swprintf_s(wchar_t *buf, size_t max_chars, const wchar_t *fmt,...) WPRINTF_ARGS(3)
std::vector< WmiInstance > WmiInstances
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
intptr_t ModuleInitState
initialization state of a module (class, source file, etc.) must be initialized to zero (e...
Status wmi_GetClassInstances(const wchar_t *className, WmiInstances &instances)
get all instances of the requested class.
i64 Status
Error handling system.
static IWbemServices * pSvc
Status ModuleShutdown(volatile ModuleInitState *initState, void(*shutdown)())
calls a user-defined shutdown function if initState is "initialized".
_COM_SMARTPTR_TYPEDEF(IWbemLocator, __uuidof(IWbemLocator))
std::map< std::wstring, VARIANT > WmiInstance
#define WARN_RETURN(status)
static ModuleInitState initState
Status ModuleInit(volatile ModuleInitState *initState, Status(*init)())
calls a user-defined init function if initState is zero.
#define RETURN_STATUS_IF_ERR(expression)