title: How to Inject DLL into ANY process?
body: <p>I'm working on way to inject a dll into any process on windows.
  I already have a code that work for my own program, like hello world or thing like that but other programs, like notepad , calc, chrome, etc..</p>
  
  <p>Program can prevent the injection of dll, so I don't know what I can do to bypass this.</p>
  
  <p>My final goal is to hook the api call of any program.</p>
  
  <p>This domains is new for me, so I'm a beginner here, if you have any resource or solution about it !</p>
  
  <p>injector.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;Windows.h&gt;
  
  int main()
  {
      // path to our dll
      LPCSTR DllPath = "D:\\projects\\standardinjection\\release\\testlib.dll";
  
      INT process_id = 14367;
      // Open a handle to target process
      HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_id);
  
      // Allocate memory for the dllpath in the target process
      // length of the path string + null terminator
      LPVOID pDllPath = VirtualAllocEx(hProcess, 0, strlen(DllPath) + 1,
          MEM_COMMIT, PAGE_READWRITE);
  
      // Write the path to the address of the memory we just allocated
      // in the target process
      WriteProcessMemory(hProcess, pDllPath, (LPVOID)DllPath,
          strlen(DllPath) + 1, 0);
  
      // Create a Remote Thread in the target process which
      // calls LoadLibraryA as our dllpath as an argument -&gt; program loads our dll
      HANDLE hLoadThread = CreateRemoteThread(hProcess, 0, 0,
          (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandleA("Kernel32.dll"),
              "LoadLibraryA"), pDllPath, 0, 0);
  
      // Wait for the execution of our loader thread to finish
      WaitForSingleObject(hLoadThread, INFINITE);
  
      std::cout &lt;&lt; "Dll path allocated at: " &lt;&lt; std::hex &lt;&lt; pDllPath &lt;&lt; std::endl;
      std::cin.get();
  
      // Free the memory allocated for our dll path
      VirtualFreeEx(hProcess, pDllPath, strlen(DllPath) + 1, MEM_RELEASE);
  
      return 0;
  }
  </code></pre>
  
  <p>my dll</p>
  
  <pre><code>#include &lt;Windows.h&gt;
  
  BOOL APIENTRY DllMain( HMODULE hModule,
                         DWORD  ul_reason_for_call,
                         LPVOID lpReserved
                       )
  {
      if (ul_reason_for_call == DLL_PROCESS_ATTACH)
          MessageBox(0, L"Hello From testlib!", L"Hello", MB_ICONINFORMATION);
  
      return TRUE;
  }
  </code></pre>
  
  <p>I'm currently on windows 10 x64
  Coming from Unix os, so Windows is pretty new for me!</p>
  
  <p>Thanks for your time !</p>