Cruel way to stop process.
Add this program to Tools menu with Arguments: $(TargetPath)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tlhelp32.h> // CreateToolhelp32Snapshot()
TCHAR szAppName[] = "ProcKill";
#pragma lib "psapi.lib"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
HANDLE hSnapShot;
HANDLE hProcess;
PROCESSENTRY32 pEntry;
TCHAR szTmp[260];
if (!*lpszCmdLine) {
MessageBox(0, "Usage: ProcKill.exe <file>", szAppName, MB_OK);
return 1;
}
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapShot) {
pEntry.dwSize = sizeof(pEntry);
if (Process32First(hSnapShot, &pEntry)) {
do {
wsprintf(szTmp, "%d %s", pEntry.th32ProcessID, pEntry.szExeFile);
if (!lstrcmpi(pEntry.szExeFile, lpszCmdLine)) {
// found it
if (MessageBox(0, pEntry.szExeFile, szAppName, MB_OKCANCEL) == IDOK) {
hProcess = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pEntry.th32ProcessID);
if (hProcess) {
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
}
}
}
} while (Process32Next(hSnapShot, &pEntry));
}
CloseHandle(hSnapShot);
}
return 0;
}
This code try to close it first normally with WM_CLOSE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tlhelp32.h> // CreateToolhelp32Snapshot()
TCHAR szAppName[] = "ProcKill";
#pragma lib "psapi.lib"
BOOL CALLBACK TerminateAppEnum(HWND hwnd, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
HANDLE hSnapShot;
HANDLE hProcess;
PROCESSENTRY32 pEntry;
TCHAR szTmp[260];
if (!*lpszCmdLine) {
MessageBox(0, "Usage: ProcKill.exe <file>", szAppName, MB_OK);
return 1;
}
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapShot) {
pEntry.dwSize = sizeof(pEntry);
if (Process32First(hSnapShot, &pEntry)) {
do {
wsprintf(szTmp, "%d %s", pEntry.th32ProcessID, pEntry.szExeFile);
if (!lstrcmpi(pEntry.szExeFile, lpszCmdLine)) {
// found it
if (MessageBox(0, pEntry.szExeFile, szAppName, MB_OKCANCEL) == IDOK) {
EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM) pEntry.th32ProcessID) ;
hProcess = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pEntry.th32ProcessID);
if (hProcess) {
if(WaitForSingleObject(hProcess, 1000)!=WAIT_OBJECT_0)
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
}
}
}
} while (Process32Next(hSnapShot, &pEntry));
}
CloseHandle(hSnapShot);
}
return 0;
}
BOOL CALLBACK TerminateAppEnum(HWND hwnd, LPARAM lParam)
{
DWORD dwID;
GetWindowThreadProcessId(hwnd, &dwID);
if (dwID == (DWORD)lParam) {
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
return TRUE;
}