windows - Executing a WMI method from C++ fails with WBEM_E_INVALID_METHOD_PARAMETERS -
i'm trying call method wmi using c++. pnamespace->callmethod(..) fails error wbem_e_invalid_method_parameters (0x8004102f).
i'm trying call method from.. namespace: root\wmi class: clevo_get method: setkbled (static = false) in params: id: 0 / name: data / type: uint32 out params: none
mof: [wmimethodid(103), implemented, read, write, description("setkbled")] void setkbled([in, description("setkbled")] uint32 data);
this code, said before, "callmethod" function never works , returns 0x8004102f error. knows wrong?
#include <windows.h> #include <iostream> #include <string> #include <wbemcli.h> #pragma comment(lib, "wbemuuid.lib") int main() { iwbemlocator *plocator = null; iwbemservices *pnamespace = 0; iwbemclassobject * pclass = null; iwbemclassobject * poutinst = null; iwbemclassobject * pinclass = null; iwbemclassobject * pininst = null; bstr path = sysallocstring(l"root\\wmi"); bstr classpath = sysallocstring(l"clevo_get"); bstr methodname = sysallocstring(l"setkbled"); bstr argname = sysallocstring(l"data"); // initialize com , connect wmi. hresult hr = coinitialize(0); hr = coinitializesecurity(null, -1, null, null, rpc_c_authn_level_default, rpc_c_imp_level_impersonate, null, eoac_none, null); hr = cocreateinstance(clsid_wbemlocator, 0, clsctx_inproc_server, iid_iwbemlocator, (lpvoid *)&plocator); hr = plocator->connectserver(path, null, null, null, 0, null, null, &pnamespace); // class object method definition. hr = pnamespace->getobject(classpath, 0, null, &pclass, null); std::cout << "namespace-class:: " << std::hex << hr << std::endl; // input-argument class object , // create instance. hr = pclass->getmethod(methodname, 0, &pinclass, null); std::cout << "get method:: " << std::hex << hr << std::endl; hr = pinclass->spawninstance(0, &pininst); std::cout << "spawn instance:: " << std::hex << hr << std::endl; // set property. variant var; var.vt = vt_i4; var.ival = 4096; //var.ival = std::stoul("0x00001000", null, 16); hr = pininst->put(argname, 0, &var, 0); std::cout << "add variable:: " << std::hex << hr << std::endl; variantclear(&var); // call method. //hr = pnamespace->execmethod(l"clevo_get", l"setkbled", 0, null, null, null, null); hr = pnamespace->execmethod(classpath, methodname, 0, null, pininst, null, null); //hr = pnamespace->execmethod(classpath, methodname, 0, null, null, null, null); std::cout << "exec result:: " << std::hex << hr << std::endl; // free resources. sysfreestring(path); sysfreestring(classpath); sysfreestring(methodname); sysfreestring(argname); pclass->release(); pininst->release(); pinclass->release(); plocator->release(); pnamespace->release(); couninitialize(); // wait finish std::cout << "done! :)"; std::cin.ignore(); return 0; } i'm trying achieve using c++ (this code snippet written in powershell , works) :
$clevo = get-wmiobject -query "select * clevo_get" -namespace "root\wmi" $clevo.setkbled( [convert]::touint32("00001000", 16) ) hope can me. highly apretiated. thanks.
Comments
Post a Comment