Failed to get object property in WMI (C ++)

I want to do something with WMI (receiving event notification), so I start with a simple example from the MSDN website:

Receive event notifications through WMI

this program receives an event notification (process creation) through WMI and calls the EventSink :: Indicate function after receiving the event.

I used the same code in the link above (copy / past) with one change: in the EventSink class, the function

HRESULT EventSink::Indicate(long lObjectCount, IWbemClassObject **apObjArray)

I added a few lines to get the property of the object (the object is returned in apObjArray):

 for (int i = 0; i < lObjectCount; i++)
    {
        VARIANT varName;
        hres = apObjArray[i]->Get(_bstr_t(L"Name"),
            0, &varName, 0, 0);
//...
    }

now the Get (...) functions return WBEM_E_NOT_FOUND (the specified property was not found) regardless of what I am looking for (I'm sure from the documentation that the properties are there ...)

Please let me know what I missed! any help is appreciated.

+5
1

Name TargetInstance, TargetInstance Name.

HRESULT EventSink::Indicate(long lObjectCount,
    IWbemClassObject **apObjArray)
{
   HRESULT hr = S_OK;
   _variant_t vtProp;

    for (int i = 0; i < lObjectCount; i++)
    {

    hr = apObjArray[i]->Get(_bstr_t(L"TargetInstance"), 0, &vtProp, 0, 0);
     if (!FAILED(hr))
     {
       IUnknown* str = vtProp;
       hr = str->QueryInterface( IID_IWbemClassObject, reinterpret_cast< void** >( &apObjArray[i] ) );
       if ( SUCCEEDED( hr ) )
       {
          _variant_t cn;
         hr = apObjArray[i]->Get( L"Name", 0, &cn, NULL, NULL );
          if ( SUCCEEDED( hr ) )
          {
            if ((cn.vt==VT_NULL) || (cn.vt==VT_EMPTY))
             wcout << "Name : " << ((cn.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
            else
             wcout << "Name : " << cn.bstrVal << endl;
          }
          VariantClear(&cn);


       }
     }
     VariantClear(&vtProp);

    }

    return WBEM_S_NO_ERROR;
}
+10

All Articles