bonsoir,

j'ai coder un petit programme en console qui me permet de sortir la liste des processus en cours d’exécution et leur process ID. j'aurais voulu aujourd'hui utiliser la fonction TerminateProcess(), mais je n'ai pas compris comment ça fonctionnait.

mon code actuel est :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
 
//  Forward declarations:
BOOL GetProcessList( );
 
int main( void )
{
  GetProcessList( );
  return 0;
}
 
BOOL GetProcessList( )
{
  HANDLE hProcessSnap;
  HANDLE hProcess;
  PROCESSENTRY32 pe32;
 
  // Take a snapshot of all processes in the system.
  hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
 
  // If the function fail return ->
  if( hProcessSnap == INVALID_HANDLE_VALUE )
  {
    printf("CreateToolhelp32Snapshot (of processes)");
    return( FALSE );
  }
 
  // Set the size of the structure before using it.
  pe32.dwSize = sizeof( PROCESSENTRY32 );
 
  // Retrieve information about the first process,
  // and exit if unsuccessful
  if( !Process32First( hProcessSnap, &pe32 ) )
  {
    printf("Process32First"); // show cause of failure
    CloseHandle( hProcessSnap );          // clean the snapshot object
    return( FALSE );
  }
 
  // Now walk the snapshot of processes, and
  // display information about each process in turn
  do
  {
    _tprintf( TEXT("\nPROCESS NAME:  %s"), pe32.szExeFile );
 
    // Retrieve the priority class
    hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
 
    if( hProcess == NULL )
      printf("OpenProcess");
 
    _tprintf( TEXT("\n  Process ID        = %d"), pe32.th32ProcessID );
 
    // List the modules and threads associated with this process
 
  } while( Process32Next( hProcessSnap, &pe32 ) );
 
  CloseHandle( hProcessSnap );
  return( TRUE );
}
quelqu'un pourrait-il me donner une piste pour m'éclairer ? merci