Enumerate through running processes and check for the executable name:
Code:
#include <windows.h>
#include <Psapi.h>
#pragma comment(lib, "Psapi.lib")
#pragma comment(lib, "User32.lib") // Just for the messagebox
#define APPLICATION_NAME "client.exe"
bool CheckProcess(DWORD processID)
{
char szProcessName[MAX_PATH];
memset(szProcessName, 0x0, sizeof(szProcessName));
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, // Less access would be fine depending on what you want to do
FALSE, processID);
if(hProcess != NULL)
{
GetModuleBaseName(hProcess, NULL, szProcessName, sizeof(szProcessName));
if(strcmp(szProcessName, APPLICATION_NAME) == 0)
{
MessageBoxA(NULL, "Found the process!", "Found", MB_OK);
return true;
}
}
CloseHandle( hProcess );
return false;
}
bool CheckAllProcesses()
{
DWORD aProcesses[1024], cbNeeded, cProcesses;
if (!EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded))
{
return false;
}
cProcesses = cbNeeded / sizeof(DWORD);
for (int i = 0; i < cProcesses; i++)
{
if(aProcesses[i] != 0)
{
CheckProcess(aProcesses[i]);
}
}
return true;
}
int main()
{
CheckAllProcesses();
return 0;
}