How can I GetProcessID by name

+1 Tatrasiel R · October 1, 2015
I am trying to make some modifications to a program that I have running on the fly and I thought that DLL Injection would be well suited for this solution.

The way that I know of executing dll injection requires the PID or ProcessID How can I get the Process ID from a program name?

#include "Functs.h"


char * DLLWeAreInjecting = "bar.dll";

char * ProcessName = "foo.exe";

    DWORD ProcessID  = GetProcessId(PROCNAME);
    HANDLE hProc;
    LPVOID paramAddr;
    HINSTANCE hDll = LoadLibrary("KERNEL32");
    typedef HINSTANCE(*fpLoadLibrary)(char*);
    fpLoadLibrary LoadLibraryAddr = (fpLoadLibrary)GetProcAddress(hDll, "LoadLibraryA");
    DWORD FindProcessId(const std::wstring& processName);

    hProc = OpenProcess(PROCESS_ALL_ACCESS, false, ProcessID);/*??????? ???????*/
    paramAddr = VirtualAllocEx(hProc, 0, strlen(DLLWeAreInjecting) + 1, MEM_COMMIT, PAGE_READWRITE);// ????? PATH ?????? ??? ? ???????? ????? ? ??????
    bool memoryWritten = WriteProcessMemory(hProc, paramAddr, DLLWeAreInjecting, strlen(DLLWeAreInjecting) + 1, NULL);

    CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)LoadLibraryAddr, paramAddr, 0, 0);
    //return memoryWritten;

This DWORD ProcessID  = GetProcessId(PROCNAME);
Doesn't get the processID by name.

Post a Reply


Oldest  Newest  Rating
0 c student · October 1, 2015
GetProcesId's parameter is a handle to the process, which I assume you acquire from the OpenProcess function.  To get a process ID, you can cycle through the list of running processes until you have a match with your process name.  Try this example here:
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator