Calling WIN32_Service::ChangeStartMode with C++
-
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