WMI ExecMethod return : WBEM_E_INVALID_METHOD_PARAMETERS

wsl

Joined
Jan 31, 2008
Messages
2
Reaction score
0
Hi, I am finding the solution for several days.
I can use "WMI Object Brower" to watch the class, so I guess the .mof file is corrent.
Anybody can provide me some idea.
Tks.

My acpimof.mof content :
[WMI,
Dynamic,
Provider("WmiProv"),
Locale("MS\\0x409"),
Description("Class used to operate methods on a package"),
guid("{ADDC0F6D-8EA1-11d1-00A0-C90629100000}")
]
class WMI_MethodTest
{
[key, read]
string InstanceName;
[read] boolean Active;

[WmiMethodId(1),
Implemented,
read, write,
Description("Return the contents of a package")
] void SetFn1([in, Description("Package Data")] uint32 Data1);

[WmiMethodId(2),
Implemented,
read, write,
Description("Set the contents of a package")
] void SetFn2([in, Description("Package Data")] uint8 Data2);

[WmiMethodId(3),
Implemented,
read, write,
Description("Generate an event containing package data")
] void SetFn3([in, Description("WMI requires a parameter")] uint32 Data3);

};

My C++ code :
CString cszQuery="WMI_MethodTest";
CString cszName="SetFn1";
CComBSTR bstrClassName ( cszQuery );
CComBSTR bstrMethodName ( cszName);
IWbemServices *pSvc = NULL;
IWbemClassObject* pClassObj = NULL;
IWbemClassObject* pInClass = NULL;
IWbemClassObject* pInParam = NULL;

hres = CoInitializeEx(0, COINIT_APARTMENTTHREADED);
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
);
IWbemLocator *pLoc = NULL;
hres = CoCreateInstance(
CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLoc);
hres = pLoc->ConnectServer(
_bstr_t("ROOT\\WMI"),
NULL, // User name. NULL = current user
NULL, // User password. NULL = current
0, // Locale. NULL indicates current
NULL, // Security flags.
0, // Authority (e.g. Kerberos)
0, // Context object
&pSvc // pointer to IWbemServices proxy
);
hres = CoSetProxyBlanket(
pSvc, // Indicates the proxy to 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
);
hres = pSvc->GetObject(bstrClassName, 0, NULL, &pClassObj, NULL);
hres = pClassObj->GetMethod(bstrMethodName, 0, &pInClass, NULL);
hres=pInClass->SpawnInstance(0, &pInParam);
VARIANT varcmd;
VariantInit(&varcmd);
varcmd.vt=VT_I4;
varcmd.lVal=1;
hres=pInParam->Put(L"Data1",0,&varcmd,0);
hres = pSvc->ExecMethod(bstrClassName, bstrMethodName, 0, NULL, pInParam, NULL, NULL);

Fail return : hres= WBEM_E_INVALID_METHOD_PARAMETERS
 
Back
Top