Friday, January 30, 2009

Given a PID, how do I find the name of the process executable?

The key here is to use OpenProcess, EnumProcessModules and GetModuleBaseName. Assume that the Process ID is in the value DWORD dwPid.

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)))
{

}
else
{

}
}
CloseHandle (hProc);
}
}

Author : Bob Moore

0 nhận xét:

Post a Comment