WMI C++ get data from object -


i implemented 1-5 steps : https://msdn.microsoft.com/en-us/library/aa390423(v=vs.85).aspx everyting works, have problem getting data object retreive query.

my code:

// step 1: -------------------------------------------------- // initialize com. ------------------------------------------  hres =  coinitializeex(0, coinit_multithreaded);  if (failed(hres)) {     //cout << "failed initialize com library. error code = 0x"      //    << hex << hres << endl;     return 1;                  // program has failed. }  // step 2: -------------------------------------------------- // set general com security levels --------------------------  hres =  coinitializesecurity(     null,      -1,                          // com authentication     null,                        // authentication services     null,                        // reserved     rpc_c_authn_level_default,   // default authentication      rpc_c_imp_level_impersonate, // default impersonation       null,                        // authentication info     eoac_none,                   // additional capabilities      null                         // reserved     );   if (failed(hres)) {     //cout << "failed initialize security. error code = 0x"      //    << hex << hres << endl;     couninitialize();     return 1;                    // program has failed. }  // step 3: --------------------------------------------------- // obtain initial locator wmi ------------------------- ploc = null;  hres = cocreateinstance(     clsid_wbemlocator,                  0,      clsctx_inproc_server,      iid_iwbemlocator, (lpvoid *) &ploc);  if (failed(hres)) {     //cout << "failed create iwbemlocator object."     //    << " err code = 0x"     //    << hex << hres << endl;     couninitialize();     return 1;                 // program has failed. }  // step 4: ----------------------------------------------------- // connect wmi through iwbemlocator::connectserver method psvc = null;  // connect root\cimv2 namespace // current user , obtain pointer psvc // make iwbemservices calls. hres = ploc->connectserver(      _bstr_t(l"root\\cimv2"), // object path of wmi namespace      null,                    // user name. null = current user      null,                    // user password. null = current      0,                       // locale. null indicates current      null,                    // security flags.      0,                       // authority (for example, kerberos)      0,                       // context object       &psvc                    // pointer iwbemservices proxy      );  if (failed(hres)) {     //cout << "could not connect. error code = 0x"      //     << hex << hres << endl;     ploc->release();          couninitialize();     return 1;                // program has failed. }  //outputdebugstring("connected root\\cimv2 wmi namespace"); // step 5: -------------------------------------------------- // set security levels on proxy -------------------------  hres = cosetproxyblanket(    psvc,                        // indicates proxy set    rpc_c_authn_winnt,           // rpc_c_authn_xxx    rpc_c_authz_none,            // rpc_c_authz_xxx    null,                        // server principal name     rpc_c_authn_level_call,      // rpc_c_authn_level_xxx     rpc_c_imp_level_impersonate, // rpc_c_imp_level_xxx    null,                        // client identity    eoac_none                    // proxy capabilities  );  if (failed(hres)) {     cout << "could not set proxy blanket. error code = 0x"          << hex << hres << endl;     psvc->release();     ploc->release();          couninitialize();     return 1;               // program has failed. } 

code above same msdn example.

problem here:

// inserted usb devices ienumwbemclassobject* penumerator = null; hres = psvc->execquery(     bstr_t("wql"),      bstr_t("select * win32_usbcontrollerdevice"),     wbem_flag_forward_only | wbem_flag_return_immediately,      null,     &penumerator);  if (failed(hres)) {     //cout << "query usb devices @ startup failed."     //    << " error code = 0x"      //    << hex << hres << endl;     psvc->release();     ploc->release();     couninitialize();     return 1;               // program has failed. }  // data query  iwbemclassobject *pclsobj = null; ulong ureturn = 0;    ostringstream os; while (penumerator){     hresult hr = penumerator->next(wbem_infinite, 1,          &pclsobj, &ureturn);     if(0 == ureturn){         break;     }     variant vtprop;     variantinit(&vtprop);     // value of accessstate property     hr = pclsobj->get(l"dependent", 0, &vtprop, 0, 0);     if (failed(hr)){                 psvc->release();         ploc->release();         couninitialize();         return 1;               // program has failed.     }     os.str("");     os.clear();     os << vtprop.bstrval;     outputdebugstring(os.str().c_str());     adddevice(os.str());//add device devices vector     variantclear(&vtprop);       pclsobj->release(); } 

exactly in place:

hr = pclsobj->get(l"dependent", 0, &vtprop, 0, 0); 

this link describes table elements: https://msdn.microsoft.com/en-us/library/aa394505(v=vs.85).aspx got dependent value. problem how dependent properties: https://msdn.microsoft.com/en-us/library/aa387884(v=vs.85).aspx example : deviceid if can very grateful!


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -