Windows下C++实现杀死某一个进程的做法
#include <wtypes.h>
#include <handleapi.h>
#include <TlHelp32.h>
BOOL KillProcessByName(LPCWSTR strProcessName) //传入进程名
{
if (NULL == strProcessName)
{
return FALSE;
}
HANDLE oHandle32Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (INVALID_HANDLE_VALUE == oHandle32Snapshot)
{
return FALSE;
}
PROCESSENTRY32W oEntry;
oEntry.dwSize = sizeof( PROCESSENTRY32W );
if (Process32FirstW(oHandle32Snapshot, &oEntry))
{
BOOL bFound = FALSE;
if (!_wcsicmp(oEntry.szExeFile, strProcessName))
{
bFound = TRUE;
}
while ((!bFound) && Process32NextW(oHandle32Snapshot, &oEntry))