使用方法:
KillProcessByTitle("注入器");
int KillProcessByTitle(const char* sWindowName)
{
HWND hWindow = FindWindow(NULL, sWindowName);
if (hWindow == NULL)
{
return 1;
}
PostMessage(hWindow, WM_CLOSE, 0, 0);//向窗口发送WM_CLOSE消息关闭对话框窗口,如果该对话框是进程的子对话框则要进行后面的关闭进程操作
DWORD dwProcessID;
HANDLE hProcess;
if (GetWindowThreadProcessId(hWindow, &dwProcessID) == 0)
{
return 2;
}
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID);
if (hProcess == NULL)
{
return 3;
}
if (!TerminateProcess(hProcess, 0))
{
return 4;
}
return 0;
}
vs根据窗口名关闭窗口或杀死窗口所在进程
最新推荐文章于 2023-01-05 09:30:00 发布