c++ - WMI SoftwareLicensingProduct class doesn't show Partial Product Key for MS Office on some systems ( Windows 10) -
using wmi softwarelicensingproduct class fetching partial product key / license key microsoft product. compatible windows vista , above. still not able retrieve key ms office on few windows10 system, rest of systems, working expected.
code :
int _tmain(int argc, _tchar* argv[]) {
hresult hres; // 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. } // initialize hres = coinitializesecurity( null, -1, // com negotiates service null, // authentication services null, // reserved rpc_c_authn_level_default, // authentication rpc_c_imp_level_impersonate, // 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. } // obtain initial locator windows management // on particular host computer. iwbemlocator *ploc = 0; hres = cocreateinstance( clsid_wbemlocator, 0, clsctx_inproc_server, iid_iwbemlocator, (lpvoid *) &ploc); if (failed(hres)) { cout << "failed create iwbemlocator object. " << "error code = 0x" << hex << hres << endl; couninitialize(); return 1; // program has failed. } iwbemservices *psvc = 0; // connect root\cimv2 namespace // current user , obtain pointer psvc // make iwbemservices calls. hres = ploc->connectserver( _bstr_t(l"root\\cimv2"), // wmi namespace null, // user name null, // user password 0, // locale null, // security flags 0, // authority 0, // context object &psvc // iwbemservices proxy ); if (failed(hres)) { cout << "could not connect. error code = 0x" << hex << hres << endl; ploc->release(); couninitialize(); return 1; // program has failed. } cout << "connected root\\cimv2 wmi namespace" << endl; // set iwbemservices proxy impersonation // of user (client) occurs. hres = cosetproxyblanket( psvc, // proxy set rpc_c_authn_winnt, // authentication service rpc_c_authz_none, // authorization service null, // server principal name rpc_c_authn_level_call, // authentication level rpc_c_imp_level_impersonate, // impersonation level 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. } // use iwbemservices pointer make requests of wmi. // make requests here: // example, query running processes ienumwbemclassobject* penumerator = null; hres = psvc->execquery( bstr_t("wql"), bstr_t("select * softwarelicensingproduct"), wbem_flag_forward_only | wbem_flag_return_immediately, null, &penumerator); if (failed(hres)) { cout << "query processes failed. " << "error code = 0x" << hex << hres << endl; psvc->release(); ploc->release(); couninitialize(); return 1; // program has failed. } else { iwbemclassobject *pclsobj; ulong ureturn = 0; while (penumerator) { hres = penumerator->next(wbem_infinite, 1, &pclsobj, &ureturn); if(0 == ureturn) { break; } variant vtprop; // value of name property hres = pclsobj->get(l"name", 0, &vtprop, 0, 0); wcout << "process name : " << vtprop.bstrval << " "; variantclear(&vtprop); variant vtprop1; // value of partialproductkey property hres = pclsobj->get(l"partialproductkey", 0, &vtprop1, 0, 0); if (vt_null != vtprop1.vt) wcout << ": " << vtprop1.bstrval << endl; else wcout<<endl; variantclear(&vtprop1); } } getch(); // cleanup // ======== psvc->release(); ploc->release(); couninitialize(); return 0; // program completed.
}
Comments
Post a Comment