当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - monitor the list of currently running processes and close my predefined exe

问题描述:

I wrote code to attempt to close "iw4m.exe" if one of listed process is running (i.e.,):

char* chos[3] = {"launcher.exe","cheat.exe","lol.exe"};

The problem is that my code only works once (when first loaded) rather than continuously like I would like it. If possible, I would like this code to monitor the list of currently running processes and close my predefined exe name when it is spawned.

#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);

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: