HANDLE info_handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //拍摄系统中所有进程的快照
if (info_handle != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32W program_info;
program_info.dwSize = sizeof(PROCESSENTRY32W); //设置结构体大小
int bResult = Process32FirstW(info_handle, &program_info); //获取所有进程中第一个进程的信息
std::wstring exeName = L"qq.exe";
while (bResult)
{
if (exeName == program_info.szExeFile && GetCurrentProcessId() != program_info.th32ProcessID)
{
// 根据进程id打开进程句柄
auto h = OpenProcess(PROCESS_TERMINATE, FALSE, program_info.th32ProcessID);
if (h)
{
::TerminateProcess(h, 0);
}
break;
}
//获得下一个进程的进程信息
bResult = Process32Next(info_handle, &program_info);
}
CloseHandle(info_handle);//关闭句柄
}
关于windows系统api查找并杀死正在运行的exe
最新推荐文章于 2024-08-10 09:32:52 发布