Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Calling WIN32_Service::ChangeStartMode with C++

Calling WIN32_Service::ChangeStartMode with C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasedebuggingjson
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qrverona
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups