Well, the code I posted allows you to enumerate process ids. Form these, you must get the exe path and then the file size with GetFileSize().
Replace:
Code:
if (_tcsicmp( pe32.szExeFile, exeFile) == 0) {
bRet = KillProcess( pe32.th32ProcessID, TRUE, (DWORD) lngTimeout );
//break;
}
with:
Code:
TCHAR szPath[MAX_PATH];
If (GetProcessPath(&pe32, szPath) &&
CheckFileSize(szPath))
{
bRet = KillProcess(pe32.th32ProcessID, TRUE, (DWORD) lngTimeout);
}
Here is the GetProcessPath function:
Code:
BOOL GetProcessPath(PROCESSENTRY32 * pe32, LPTSTR szPath)
{
HANDLE hModules;
MODULEENTRY32 me32 = { 0 };
BOOL bResult;
hModules = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pe32->th32ProcessID);
me32.dwSize = sizeof(me32);
szPath[0] = '\0';
if (hModules && Module32First(hModules, &me32)
{
while (TRUE)
{
if (stricmp(pe32->szExeFile, me32.szModule) == 0 ||
stricmp("", me32.szModule) == 0)
{
lstrcpy(szPath, me32.szExePath);
break;
}
if (!Module32Next(hModules, &me32)) break;
}
}
if (hModules) CloseHandle(hModules);
return (szPath[0] != '\0');
}
You must provide the CheckFileSize function. It should look something like:
Code:
BOOL CheckFileSize(LPCTSTR szPath)
{
HANDLE hFile = CreateFile(szPath, ...);
DWORD cbFileSize = GetFileSize(hFile, NULL);
return (cbFileSize == SETI_SIZE);
}
Note: I'm assuming you are running 2000 or XP.