If you just judge the name of the EXE (do not need to judge the path), you can omit enumprocess, because the pe32.szexefile already have the name of the EXE, because there is no path, so the function enumprocess to get the full path. This is a little simpler.
BOOL CALLBACK Enumwinproc (HWND hwnd, LPARAM LPARAM)
{
DWORD Dwid;
GetWindowThreadProcessId (hwnd, &DWID);
if (Dwid = = (DWORD) lParam) {
PostMessage (hwnd, wm_quit, 0, 0);
return FALSE;
}
return TRUE;
}
void Killprogram (LPCSTR exename)
{
Char *file;
HANDLE Hprocesssnap;
PROCESSENTRY32 pe32;
if (! EXEName | | ! Exename[0])
Return
File = STRRCHR (exename, ' \ \ ');
if (file!=0) exename = file+1;
Hprocesssnap = CreateToolhelp32Snapshot (
th32cs_snapprocess, 0);
if (Hprocesssnap = = (HANDLE)-1) return;
memset (&pe32, 0, sizeof (PE32));
pe32.dwsize = sizeof (PROCESSENTRY32);
if (Process32First (Hprocesssnap, &pe32))
{
do {
memset (&me32, 0, sizeof (ME32));
me32.dwsize = sizeof (ME32);
File = STRRCHR (pe32.szexefile, ' \ \ ');
File = file? File+1:pe32.szexefile;
if (Strcmpi (file,exename) ==0) {
EnumWindows ((Wndenumproc) Enumwinproc,
PE32.TH32PROCESSID);
}
}
while (Process32Next (HPROCESSSNAP,&PE32));
}
CloseHandle (HPROCESSSNAP);
}