0

the following vbscript gives the number of rows returned by the WMI query.

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PnPSignedDriver",,0)
Wscript.Echo colItems.count

Same thing I need to achieve in C++.

In C++, passing the query using IWbemServices->ExecQuery method

....
//initializing and connecting WMI
....
hr = services->ExecQuery(bstr_t("WQL"), bstr_t(strClass), WBEM_FLAG_FORWARD_ONLY |   WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &results);

I tried the above but dont know how to get the row count of the query. Can someone please suggest how to get it done in C++

Arun
  • 2,247
  • 3
  • 28
  • 51

2 Answers2

2

AFAIK that property is not present in the WMI COM API, to obtain the number of records you must use the IEnumWbemClassObject interface and count the instances returned your self.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
0

You need to iterate the results:

IWbemClassObject* pclsObj = NULL;
int uRows = 0;

while (pEnumerator)
{
  HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);

  if (0 == uReturn)
  {
     break;
  }

  uRows++;
}

uRows is your "row count".

Mecanik
  • 1,539
  • 1
  • 20
  • 50