title: C++ get network utilization like task manager
body: <p>Im trying to get the network adapter utilization as shown in task manager.
  I've now tried to use WMI, and i'm able to get bytes received per second/ bytes sent per second. Is there any way to get the pre calculated value shown in task manager(0-100%), or can i use these to calculate that value?</p>
  
  <p><a href="https://i.stack.imgur.com/3ObEc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3ObEc.png" alt="enter image description here"></a></p>
  
  <pre><code>IEnumWbemClassObject* pEnumerator = NULL;
  hres = pSvc-&gt;ExecQuery(
      bstr_t("WQL"),
      bstr_t("SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface"),
      WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
      NULL,
      &amp;pEnumerator);
  
  if (FAILED(hres))
  {
      cout &lt;&lt; "Query for operating system name failed."
          &lt;&lt; " Error code = 0x"
          &lt;&lt; hex &lt;&lt; hres &lt;&lt; endl;
      pSvc-&gt;Release();
      pLoc-&gt;Release();
      CoUninitialize();
      return 1;               // Program has failed.
  }
  
  
  // Get the data from the query
  IWbemClassObject *pclsObj = NULL;
  ULONG uReturn = 0;
  
  while (pEnumerator)
  {
  
      HRESULT hr = pEnumerator-&gt;Next(WBEM_INFINITE, 1,
          &amp;pclsObj, &amp;uReturn);
  
      if (0 == uReturn)
      {
      break;
      }
  
  
      VARIANT vtProp;
      VariantInit(&amp;vtProp);
  
      hr = pclsObj-&gt;Get(L"Name", 0, &amp;vtProp, 0, 0);
      wcout &lt;&lt; " network adapter : " &lt;&lt; vtProp.bstrVal &lt;&lt; endl;
      VariantClear(&amp;vtProp);
  
      hr = pclsObj-&gt;Get(L"BytesReceivedPerSec", 0, &amp;vtProp, 0, 0);        
      wcout &lt;&lt; " BytesReceivedPerSec  : " &lt;&lt; vtProp.bstrVal &lt;&lt; endl;
      VariantClear(&amp;vtProp);
  
      hr = pclsObj-&gt;Get(L"BytesSentPerSec", 0, &amp;vtProp, 0, 0);        
      wcout &lt;&lt; " BytesSentPerSec  : " &lt;&lt; vtProp.bstrVal &lt;&lt; endl;
      VariantClear(&amp;vtProp);
  
      hr = pclsObj-&gt;Get(L"Timestamp_Sys100NS", 0, &amp;vtProp, 0, 0);
      wcout &lt;&lt; " Timestamp_Sys100NS  : " &lt;&lt; vtProp.bstrVal &lt;&lt; endl;
      VariantClear(&amp;vtProp);
  
  
  
  
      pclsObj-&gt;Release();
  }
  </code></pre>