Dear all, I'm writing a small application that manages the Themes service using WMI. Unfortunately I have problems with the parameters. The API documentation says that it is a string, but I wasn't able to find a solution. ExecMethod returns : WBEM_E_INVALID_METHOD_PARAMETERS = 0x8004102f I have realized that the parameter is not well formatted, but I'm not able to find any tip. Notice that the same code querying for "Win32_Process" and calling "Create" using CommandLine as parameter and "notepad.exe" as value, runs correctly. To test it, it is enough to replace the strings text. Thanks Daniele // some WMI initialization here..... IWbemClassObject *pClass = NULL; IWbemClassObject *pInParams = NULL; IWbemClassObject *pInParamInstance = NULL; IWbemClassObject *pOutParams = NULL; IEnumWbemClassObject *pEnumerator = NULL; IWbemClassObject *pInstance = NULL; DWORD dwCount = 0; HRESULT hres; BSTR bstrChangeStartMode = L"ChangeStartMode"; BSTR bstrClassName = L"Win32_Service"; BSTR bstrParamName = L"StartMode"; BSTR bstrParamValue = L"Automatic"; VARIANT varValue; VARIANT varReturnValue; // query for the proper object to which apply the method hres = pSvc->ExecQuery( bstr_t("WQL"), bstr_t("SELECT * FROM Win32_Service Where Name = 'Themes'"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); while (pEnumerator->Next( WBEM_INFINITE, 1,&pInstance, &dwCount) == WBEM_S_NO_ERROR) { // get method class hres = pSvc->GetObject( bstrClassName, 0, NULL, &pClass, NULL); // prepare method params if (pClass) hres = pClass->GetMethod(bstrChangeStartMode,0,&pInParams,NULL); else { printf("Unable to get method '%s' from '%s' class\n", CString(bstrChangeStartMode), CString(bstrClassName)); return -1; } if (pInParams) hres = pInParams->SpawnInstance(0, &pInParamInstance); else { printf("Unable to get params for from %s::%s()\n", CString(bstrClassName), CString(bstrChangeStartMode)); return -2; } // analyzing the method paramenter (debug purposes only) printf("Analyzing the %s::%s() paramenter(s)...\n", CString(bstrClassName), CString(bstrChangeStartMode)); hres = pInParams->BeginEnumeration(0); BSTR
qrverona
Posts
-
Calling WIN32_Service::ChangeStartMode with C++ -
Getting IP Address through WMIDear all, I'm writing a C++ (.NET 2003 with MFC) application that needs to query several data through WMI. I have a problem while accessing to the "IPAddress" data managed by the Win32_NetworkAdapterConfiguration WMI class. It is stored as a string array, the first Get returns me this information, but I did not found any issue on how to get the array. bool CMyDoc::GetWMIItemValue( IWbemClassObject *pInstance, LPCWSTR pItemName, CStringArray& strArray) { VARIANT val; LONG lFlavour; HRESULT hGet; CIMTYPE cimType; VariantInit(&val); strArray.RemoveAll(); hGet = pInstance->Get( pItemName, 0, &val, // val cannot hold the result &cimType, // returns 2008 = string array &lFlavour); // returns 0 if (hGet == WBEM_S_NO_ERROR) { if (cimType == (CIM_STRING | CIM_FLAG_ARRAY)) { // val holds 0x2008 too, unusable // how can I access the array? } } Thank you for you help... PS: Using C# is a piece of cake, but my application has been developed in C++ and I cannot convert it. Daniele
-
Disabling dialog button from within the ON_BN_CLICKED handlerI'm sorry, it desn't work. Ciao... Daniele
-
Disabling dialog button from within the ON_BN_CLICKED handlerI'm sorry, it desn't work. Ciao... Daniele