Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. HANDLE GetProcessHandle( char* szProcessName )
  2. {
  3.     PROCESSENTRY32 Entrada;
  4.     HANDLE Final, SnapShot;
  5.     Entrada.dwSize = sizeof(PROCESSENTRY32);
  6.     SnapShot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
  7.  
  8.     Process32First( SnapShot, &Entrada );
  9.  
  10.     if( !strcmp( szProcessName, Entrada.szExeFile ) )
  11.         goto pegapid;
  12.  
  13.     while(Process32Next( SnapShot, &Entrada ))
  14.     {
  15.         if(!strcmp( szProcessName, Entrada.szExeFile ))
  16.         {
  17.             goto pegapid;
  18.         }
  19.     }
  20.  
  21.     goto final;
  22.  
  23. pegapid:
  24.  
  25.     Final = OpenProcess( PROCESS_ALL_ACCESS, false, Entrada.th32ProcessID );
  26.     printf( "Process found !\n" );
  27.  
  28.     return Final;
  29.  
  30. final:
  31.     printf( "Process not found !\n" );
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement