Hi, I've done a little program that looks if another process is executed.. if it is not executed, it executes the process. And it starts again ... looping ;)
it enumerates all running processes, then it checks if one of those is Limiter.exe, if so, it keeps looping, else it executes Limiter.exe and start again looping.
It seems to work fine but.. sometimes...it does not... if I kill Limiter.exe several times, it can happen that, it is not executed anymore after I killed it.. and my program (the keeper alive) keeps looping without execute Limiter.exe anymore..Code:#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "psapi.h"
#include <string.h>
int ProcessFinder (void);
int main(void)
{
while( 1 ){
sleep(200);
ProcessFinder();
}// end while
return 0;
}
/* --------- PROCESS FINDER --------- */
int ProcessFinder (void){
char szProcessName[MAX_PATH] = "BianConiglioRulez";
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
double tmp;
char tempid[MAX_PATH];
char pid[MAX_PATH];
int PidNumber = 0;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return -1;
cProcesses = cbNeeded / sizeof(DWORD);
for ( i = 0; i < cProcesses; i++ ) // cerca tutti i processi
{
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE,
aProcesses[i] );
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess,
&hMod,
sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess,
hMod,
szProcessName,
sizeof(szProcessName));
}
}
if (!strcmp(szProcessName, "Limiter.exe"))
{
//printf("found\n");
return 0;
}
CloseHandle( hProcess );
}// end FOR
//printf("Not found.. executing\n");
ShellExecute(NULL,
"open",
"C:\\Limiter\\Limiter.exe",
NULL,
NULL,
SW_SHOWNORMAL);
return 0;
}
Can you find some "logic" bug in the program? I cant :(