1、首先需要include一个文件,如下:
#include <tlhelp32.h>
2、参看以下代码:
#include <tlhelp32.h>
2、参看以下代码:
- Code: Select all
//遍历系统所有进程,杀死联众世界
HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 *info = new PROCESSENTRY32;
info->dwSize = sizeof(PROCESSENTRY32);
if(Process32First(handle,info))
{
if(GetLastError()==ERROR_NO_MORE_FILES )
{
AfxMessageBox("No More Process");
}
else
{
//先判断第一个
CString processname;
UINT processid;
HANDLE h;
processname = info->szExeFile;
if (processname == "GLWorld.exe")
{
//取得进程ID,然后杀掉进程
processid = info->th32ProcessID;
h = OpenProcess(PROCESS_ALL_ACCESS, TRUE, processid);
if(h != NULL)
{
TerminateProcess(h, 0);
}
}
else
{
while(Process32Next(handle,info)!=FALSE)
{
processname = info->szExeFile;
if (processname == "GLWorld.exe")
{
//取得进程ID,然后杀掉进程
processid = info->th32ProcessID;
h = OpenProcess(PROCESS_ALL_ACCESS, TRUE, processid);
if(h != NULL)
{
TerminateProcess(h, 0);
break;
}
}
}
}
}
}
CloseHandle(handle);