title: Enumerating partitions drive letter using WMI in vc++
body: <p>I want to get the system drive letter of all partitions on the computer, except the active partition, using WMI, this is what I've came up so far( I don't know how to get the drive letter&amp; how to check if they are all HDDs or system drives so I Don't get any CD-ROM here):</p>
  
  <pre><code> std::vector&lt;CString&gt; GetPartitionsVector(bool bCoInit   = false  )
  {
      std::vector&lt;CString&gt; partVect;
      HRESULT hres = NULL;
      if(bCoInit)
      {
  
          hres =  CoInitializeEx(0, COINIT_MULTITHREADED); 
          if (FAILED(hres))
          {
              goto end_routine;
          }
  
          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
              );
  
  
          if (FAILED(hres))
          {
              goto end_routine;
          }
      }
  
  
      IWbemLocator *pLoc = NULL;
  
      hres = CoCreateInstance(
          CLSID_WbemLocator,             
          0, 
          CLSCTX_INPROC_SERVER, 
          IID_IWbemLocator, (LPVOID *) &amp;pLoc);
  
      if (FAILED(hres))
      {
          goto end_routine;
      }
  
  
      IWbemServices *pSvc = NULL;
  
      hres = pLoc-&gt;ConnectServer(
          _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
          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 
          &amp;pSvc                    // pointer to IWbemServices proxy
          );
  
      if (FAILED(hres))
      {
          goto end_routine;
      }
  
      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 
          );
  
      if (FAILED(hres))
      {
          goto end_routine;
      }
  
      // Step 6: --------------------------------------------------
      // Use the IWbemServices pointer to make requests of WMI ----
  
      // For example, get the name of the operating system
      IEnumWbemClassObject* pEnumerator = NULL;
      hres = pSvc-&gt;ExecQuery(
          bstr_t("WQL"), 
          bstr_t("SELECT * FROM Win32_DiskPartition"),                // Win32_DiskPartition
          WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
          NULL,
          &amp;pEnumerator);
  
      if (FAILED(hres))
      {
          pSvc-&gt;Release();
          pLoc-&gt;Release();
  
          goto end_routine;
      }
  
      // Step 7: -------------------------------------------------
      // Get the data from the query in step 6 -------------------
  
      IWbemClassObject *pclsObj;
      ULONG uReturn = 0;
  
      while (pEnumerator)
      {
          HRESULT hr = pEnumerator-&gt;Next(WBEM_INFINITE, 1, 
              &amp;pclsObj, &amp;uReturn);
  
          if(0 == uReturn)
          {
              break;
          }
  
          VARIANT vtProp;
  
          // Get the value of the Name property
          hr = pclsObj-&gt;Get(L"BootPartition", 0, &amp;vtProp, 0, 0);
  
          if(!vtProp.boolVal)     //if this is not boot partition, get some more
          {
              hr = pclsObj-&gt;Get(L"BootPartition", 0, &amp;vtProp, 0, 0);
              if(FAILED(hr))
              {
                  //log here
              }
              hr = pclsObj-&gt;Get(L"SystemName", 0, &amp;vtProp, 0, 0);
            if(!FAILED(hr))
                partVect.push_back(vtProp.bstrVal);
          }
  
  
  
  
          VariantClear(&amp;vtProp);
          pclsObj-&gt;Release();
      }
  
      // Cleanup
      // ========
  
      pSvc-&gt;Release();
      pLoc-&gt;Release();
      pEnumerator-&gt;Release();
  
  
  
  end_routine:
  
      if(bCoInit)
      {
          CoUninitialize();
      }
      return partVect;
  }
  </code></pre>