title: C++ Getting handle from process without OpenProcess()
body: <p>Hi i was wondering how could i get specific handle from process.</p>
  
  <p>I mean i have dll what i inject into process for example. "example.exe" which has handles on various other processes and i would want to get handle to "exampleHandle.exe" which "example.exe" already has.</p>
  
  <p>basically i would "steal" the handle, so getting the handle without opening new one.</p>
  
  <p>This is how i did it with OpenProcess()</p>
  
  <pre><code>void ProcMem::Process(char* ProcessName)
  {
      HANDLE hPID = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
      PROCESSENTRY32 ProcEntry;
      ProcEntry.dwSize = sizeof(ProcEntry);
      do
          if (!strcmp(ProcEntry.szExeFile, ProcessName))
          {
              dwPID = ProcEntry.th32ProcessID;
              CloseHandle(hPID);
              hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID);
              return;
          }
      while (Process32Next(hPID, &amp;ProcEntry));
  
      cout &lt;&lt; "\nCouldn't find process\n";
      system("pause");
      exit(0);
  }
  </code></pre>