title: C++ : Disabling a device driver in Windows
body: <p>Can anybody help me to tell why this code is not disabling the <code>cdrom driver</code>?It builds correctly.I debugged each line everything works perfectly. I have removed the error handling code and the cleanup code.</p>
  
  <pre><code>int main(int argc, char* argv[])
  {
  
       IWbemServices *pSvc = NULL;
   HRESULT hres = CoInitializeEx(0, COINIT_MULTITHREADED);
  
      hres = CoInitializeSecurity(NULL,-1,NULL,NULL,RPC_C_AUTHN_LEVEL_DEFAULT,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE,NULL);    
      IWbemLocator *pLoc = NULL;
      hres = CoCreateInstance(CLSID_WbemLocator,0,CLSCTX_INPROC_SERVER,IID_IWbemLocator,LPVOID *)&amp;pLoc);
  
      hres = pLoc-&gt;ConnectServer(_bstr_t(L"ROOT\\CIMV2"),NULL,NULL,0,NULL,0,0,&amp;pSvc);
  
      BSTR MethodName = SysAllocString(L"StopService");
      BSTR ClassName = SysAllocString(L"Win32_SystemDriver");
  
      IWbemClassObject* pClass = NULL;
      hres = pSvc-&gt;GetObject(ClassName, 0, NULL, &amp;pClass, NULL);
      IWbemClassObject* pInParamsDefinition = NULL;
      hres = pClass-&gt;GetMethod(MethodName, 0, &amp;pInParamsDefinition, NULL);
  
      VARIANT varCommand;
  
      IWbemClassObject* pOutParams = NULL;
      hres = pSvc-&gt;ExecMethod(L"Win32_SystemDriver.Name=\"cdrom\"", MethodName, 0,
      NULL,NULL, &amp;pOutParams, NULL);
  
      VARIANT varReturnValue;
      hres = pOutParams-&gt;Get(L"ReturnValue", 0, &amp;varReturnValue, NULL, 0);
      if (!FAILED(hres))
      wcout &lt;&lt; "ReturnValue " &lt;&lt; varReturnValue.intVal &lt;&lt; endl;
      VariantClear(&amp;varReturnValue);
  
      // Clean up    
      SysFreeString(ClassName);
      SysFreeString(MethodName);  
      return 0;
  }
  </code></pre>
  
  <p>Please help..</p>