Exemplo n.º 1
0
void __fastcall TFormMain::NMUDP1DataReceived(TComponent *Sender,
      int NumberBytes, AnsiString FromIP, int Port)
{
char * buf = (char*)malloc(5000);
int bytesread = 0;
NMUDP1->ReadBuffer( buf, 5000, bytesread );

char *p = strtok( buf, "\n" );
String proc = p;
proc = proc.Trim();

// procura processo ( a primeira linha da mensagem é o nome do processo )
for ( unsigned i = 0; i < Processos.size(); i++ )
  if ( proc.AnsiCompareIC(Processos[i]) == 0 )
    { // achou, resseta watchdog
    WDCnt[i] = 0;

    if ( i == (unsigned)ProcIndex ) // mostra se for o processo selecionado
      {
      memoMens->Lines->Clear();
      memoMens->Lines->Add( proc );
      while ( ( p = strtok(NULL, "\n")) != NULL )
         {
         memoMens->Lines->Add(p);
         }
      }
    break;
    }

free(buf);
}
Exemplo n.º 2
0
bool ProcessoExecutando(String ExeFile, DWORD &id)
{
bool achou = false;
HANDLE snap;
PROCESSENTRY32 pre;
bool ret;

DWORD idProcess[200];
DWORD cbNeeded;

EnumProcesses(
  idProcess, // array of process identifiers
  sizeof(idProcess), // size of array
  &cbNeeded // number of bytes returned
  );

unsigned i;
for ( i = 0; i < (int)cbNeeded / sizeof(DWORD); i++ )
  {
  HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, idProcess[i] );
  if ( hProcess != NULL )
    {
    HMODULE hmp[100];
    DWORD dwSize;
    int ret = EnumProcessModules( hProcess, hmp, sizeof(hmp), &dwSize );
    if ( ret != 0 )
      {
      char buf[1000];
      GetModuleFileNameEx( hProcess, hmp[0], buf, sizeof(buf) - 1 );

      if( ExeFile.AnsiCompareIC(buf) == 0 )
        {
        id = idProcess[i];
        achou = true;
        CloseHandle( hProcess );
        break;
        }
      }
    CloseHandle( hProcess );
    }
  }

return achou;
}