Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Detect if a process is running

Name: Anonymous 2007-04-26 0:41 ID:BFlCOmid

How do you detect if a process is running by its name in Windows? In other words be able to input "program.exe" into a function and have it say if it is running.

Preferably in C++, but alternate languages are ok.

Name: Anonymous 2007-04-26 4:51 ID:zeqRwc7V

This is adapted from a program I use to do some in-memory patching of a particular process.


// returns number of processes of specified name running
// or -1 if error
int process_running_count(char * processname)
{
  int process_count = 0;
  HANDLE snapshot;
  PROCESSENTRY32 pe;

  snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);

  pe.dwSize = sizeof(PROCESSENTRY32);
  if(Process32First(snapshot, &pe)==FALSE)
    return -1;

  do {
    if (_stricmp(process_name, pe.szExeFile)==0) // case insensitive comparison
      process_count++;
  } while(Process32Next(snapshot, &pe)!=FALSE);

  return process_count;

}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List