title: C++ - Remove Injected DLL
body: <p>I used this code which I found somewhere on internet:</p>
  
  <pre><code>    void InjectDLL()
  {
      char *dllName = "C:\\Project2.dll";
  
      HANDLE proc = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_SET_INFORMATION | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_CREATE_THREAD, FALSE, PID);
  
      LPVOID LoadLibAddr = (LPVOID)GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA");
      LPVOID dereercomp = VirtualAllocEx(proc, NULL, strlen(dllName) + 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
      WriteProcessMemory(proc, dereercomp, dllName, strlen(dllName) + 1, NULL);
      HANDLE asdc = CreateRemoteThread(proc, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddr, dereercomp, 0, NULL);
  
      WaitForSingleObject(asdc, INFINITE);
      VirtualFreeEx(proc, dereercomp, strlen(dllName) + 1, MEM_RELEASE);
      CloseHandle(asdc);
      CloseHandle(proc);
  }
  </code></pre>
  
  <p>Everything work perfectly fine, but after I finished things I had to do I'd like to remove injected dll, either from program which injects dll or dll itself.</p>