c++强制结束进程

来源:互联网 发布:pro结尾的域名 编辑:程序博客网 时间:2024/05/18 21:43
// ConsoleApplication3.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <iostream>#include <string>#include<windows.h>#include<iostream>#include<tlhelp32.h>using namespace std;int _tmain(int argc, _TCHAR* argv[]){LPCTSTR strProcessName=L"QQMusic.exe";if (NULL == strProcessName){return FALSE;}HANDLE handle32Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);if (INVALID_HANDLE_VALUE == handle32Snapshot){return FALSE;}PROCESSENTRY32 pEntry;pEntry.dwSize = sizeof(PROCESSENTRY32);//Search for all the process and terminate itif (Process32First(handle32Snapshot, &pEntry)){BOOL bFound = FALSE;if (!_tcsicmp(pEntry.szExeFile, strProcessName)){bFound = TRUE;}while ((!bFound) && Process32Next(handle32Snapshot, &pEntry)){if (!_tcsicmp(pEntry.szExeFile, strProcessName)){bFound = TRUE;}}if (bFound){CloseHandle(handle32Snapshot);HANDLE handLe = OpenProcess(PROCESS_TERMINATE, FALSE, pEntry.th32ProcessID);BOOL bResult = TerminateProcess(handLe, 0);return bResult;}}CloseHandle(handle32Snapshot);return false;}

原创粉丝点击