如果列出的进程之一正在运行(即,),我编写的代码试图关闭“iw4m.exe”:
char* chos[3] = {"launcher.exe","cheat.exe","lol.exe"};
问题是我的代码只能运行一次(首次加载时),而不是像我希望的那样连续运行。如果可能,我希望此代码监视当前正在运行的进程列表,并在生成时关闭我的预定义exe名称。
#include "StdInc.h"
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
#include <stdio.h>
void find_Proc() {
HANDLE proc_Snap;
HANDLE proc_iw4;
HANDLE proc_iw4term;
PROCESSENTRY32 pe32;
PROCESSENTRY32 pe32iw4;
int i;
char* chos[3] = {"launcher.exe","cheat.exe","lol.exe"};
char* iw4m = "iw4m.exe";
proc_iw4 = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
proc_Snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
pe32.dwSize = sizeof(PROCESSENTRY32);
pe32iw4.dwSize = sizeof(PROCESSENTRY32);
for(i = 0; i < 3 ; i++) {
Process32First(proc_Snap , &pe32);
do {
if(!strcmp(chos[i],pe32.szExeFile)) {
MessageBox(NULL,"CHEAT DETECTED","ERROR",NULL);
Process32First(proc_iw4,&pe32iw4);
do {
if (!strcmp(iw4m,pe32iw4.szExeFile)) {
proc_iw4term = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pe32iw4.th32ProcessID);
if (proc_iw4term != NULL)
TerminateProcess(proc_iw4term, 0);
CloseHandle(proc_iw4term);
}
} while(Process32Next(proc_iw4, &pe32iw4));
}
} while(Process32Next(proc_Snap, &pe32));
}
CloseHandle(proc_Snap);
CloseHandle(proc_iw4);
}