title: Get Memory , CPU for process C++
body: <p>I need to get all available information on each process running in the computer
  that includes : CPU information such as cpu usage and so on with Memory.</p>
  
  <p>I've used CreateToolhelp32Snapshot and Process32Entry to obtain information such as Process name, Process ID, num of threads.</p>
  
  <p>then used OpenProcess with the ID i got from above to get memory info.</p>
  
  <p>Code runs good. But OpenProcess returns Denied_access on a lot of Processes so i wasnt able to get their Memory info which is not good.</p>
  
  <p>But it is possible since i can get this information from psutil libary (Python)</p>
  
  <p>I've come accros WMI too but doesn't give a lot info about the memory..</p>
  
  <p>Is there any method to bypass OpenProcess's Access denied and still get the info?</p>
  
  <p>Is there another method to get all this information per Process?</p>
  
  <p>And if there isn't any good solutions for above :
  There is option to run python script and get the info to a matrix which is coded in C++ upon the memory? I don't want to write it to a file and read in C++ from the file because it is very slow and time is critical..</p>
  
  <p>This is the code if its matter : </p>
  
  <pre><code>void GetMemoryInfo(DWORD processID, int index, ProcessT list[])
  {
      HANDLE hProcess;
      PROCESS_MEMORY_COUNTERS pmc;
  
  // Print the process identifier.
  
  printf("\nProcess ID: %u\n", processID);
  
  
  
  // Print information about the memory usage of the process.
  
      hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID);
      if (NULL == hProcess)
          cout &lt;&lt; GetLastError();
  
      if (GetProcessMemoryInfo(hProcess, &amp;pmc, sizeof(pmc)))
      {
          list[index].pMemory.PagefileUsage = pmc.PagefileUsage;
          list[index].pMemory.PeakPagefileUsage = pmc.PeakPagefileUsage;
          list[index].pMemory.PeakWorkingSetSize = pmc.PeakWorkingSetSize;
          list[index].pMemory.QuotaNonPagedPoolUsage = pmc.QuotaNonPagedPoolUsage;
          list[index].pMemory.QuotaPagedPoolUsage = pmc.QuotaPagedPoolUsage;
          list[index].pMemory.QuotaPeakNonPagedPoolUsage = pmc.QuotaPeakNonPagedPoolUsage;
          list[index].pMemory.QuotaPeakPagedPoolUsage = pmc.QuotaPeakPagedPoolUsage;
          list[index].pMemory.PageFaultCount = pmc.PageFaultCount;
      }
  }
  int showProcessInformation(ProcessT list[]) {
      int i = 0;
      HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
      if (hSnapshot) {
          PROCESSENTRY32 pe32;
          pe32.dwSize = sizeof(PROCESSENTRY32);
          if (Process32First(hSnapshot, &amp;pe32)) {
              do {
                  list[i].pExeName = pe32.szExeFile;
                  list[i].pID = pe32.th32ProcessID;
                  list[i].thredcnt = pe32.cntThreads;
                  GetMemoryInfo(list[i].pID, i, list);
                  i++;
  
          } while (Process32Next(hSnapshot, &amp;pe32));
      }
      CloseHandle(hSnapshot);
  }
  
  return i;
  </code></pre>
  
  <p>}</p>