1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <iostream>
#define _WIN32_WINNT 0x06000000 //Windows 7
#define WINVER 0x601 //Window 7
#define WIN32_LEAN_AND_MEAN //Prevents Older Header Files From Being Included
#include <windows.h>
#include <winbase.h>
#include <Objbase.h>
#include <wbemidl.h>
#include <OleAuto.h>
int main()
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);
IWbemLocator* pLocation = NULL;
IWbemServices* pService = NULL;
BSTR Query = SysAllocString(L"Select * From Win32_Product Where Name Like '%Java%'"); ///This Is In WQL Which Is Not Unlike SQL.
IEnumWbemClassObject* ClassEnum = NULL;
IWbemClassObject* ClassObj = NULL;
const ULONG NumItems = 1;
ULONG ItemsRet = 0;
VARIANT Version;
VariantInit(&Version);
V_VT(&Version) = VT_BSTR;
CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*) &pLocation);
pLocation->ConnectServer(BSTR(L"ROOT\\CIMV2"), NULL, NULL, 0, NULL, 0, 0, &pService);
pService->ExecQuery(BSTR(L"WQL"), BSTR(Query), WBEM_FLAG_BIDIRECTIONAL, NULL, &ClassEnum);
while(ClassEnum->Next(WBEM_INFINITE, NumItems, &ClassObj, &ItemsRet) == WBEM_S_NO_ERROR)
{
ClassObj->Get(BSTR(L"Version"), 0, &Version, NULL, NULL);
std::wcout << L"Version is: " << Version.bstrVal << L"\n";
ClassObj->Release();
}
SysFreeString(Query);
if(ClassEnum != NULL)
{
ClassEnum->Release();
}
if(pService != NULL)
{
pService->Release();
}
if(pLocation != NULL)
{
pLocation->Release();
}
CoUninitialize();
return 0;
}
|