I just wrote a C function to do that (stolen from some other support thread). It seems to be working fine.
/* Try to kill a process with a given filename (e.g. foo.exe), that is not your current process!
* Return 1 if it was killed, -1 if it was found but could not be killed, 0 if it was not found.
*/
__declspec(dllexport) LONG32 __stdcall killProcessByName(const char *filename)
{
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
PROCESSENTRY32 pEntry;
DWORD myProcessID;
int ret = 0;
pEntry.dwSize = sizeof(pEntry);
BOOL hRes = Process32First(hSnapShot, &pEntry);
myProcessID = GetCurrentProcessId();
while (hRes)
{
if (stricmp(pEntry.szExeFile, filename) == 0)
{
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0,
(DWORD)pEntry.th32ProcessID);
if (hProcess != NULL)
{
if (pEntry.th32ProcessID != myProcessID)
{
if (TerminateProcess(hProcess, 9))
ret = 1;
else
ret = -1;
}
CloseHandle(hProcess);
if (ret != 0) break;
}
}
hRes = Process32Next(hSnapShot, &pEntry);
}
CloseHandle(hSnapShot);
return ret;
}
I declare that in PB (given that I am compiling as ANSI) as:
function long KillProcessByName(String filename) library "mylib.dll" alias for "killProcessByName;ansi"