The key here is to use OpenProcess, EnumProcessModules and GetModuleBaseName. Assume that the target Process ID is in the value dwPid, which is a DWORD:
HANDLE hProc;
char szProcessName [80];
HMODULE ahMod [10];
DWORD dwNeeded;
hProc = OpenProcess (PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,
FALSE,
dwPid);
if (hProc)
{
if (EnumProcessModules (hProc,
ahMod,
sizeof(ahMod),
&dwNeeded))
{
if (GetModuleBaseName (hProc,
ahMod[0],
szProcessName,
sizeof(szProcessName)))
{
<success>
}
else
{
<failure>
}
}
CloseHandle (hProc);
}
Download