/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include "EnumProc.h"

int fnd = 0;

char searchstr[256];
char actionstr[256];


BOOL __stdcall Proc( DWORD dw, WORD alwaysZero, LPSTR lpstr, LPARAM lParam )
{
  if( strcmp( lpstr, searchstr) == 0 ) fnd = 1;
  return 1;
}

int main(int argc, char *argv[])
{
  int i;
  strcpy( searchstr, argv[1] );
  printf( "looking for %s\n", searchstr );
  strcpy( actionstr, "" );
  for (i = 2; i < argc; i++) {
     if ( i > 2 ) strcat( actionstr, " " );
     strcat( actionstr, argv[i] );
  }
  printf( "will do %s\n", actionstr );
  while (1) {
    fnd = 0;
    EnumProcs( Proc, 0 );
    if ( !fnd ) {
        system( actionstr );
    }
    Sleep(2000);
  }
  return 0;
}
