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
|
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <tlhelp32.h>
int main()
{
HANDLE hSnapShot;
PROCESSENTRY32 pe;
FILE * f_rapport;
f_rapport = fopen("rapport.txt", "w"); /* Ouverture du fichier rapport.txt ("rapport.txt") pour écriture ("w"). */
/* Si le fichier n'existe pas, il sera créé. */
if (f_rapport == NULL)
{
/* En cas d'erreur d'ouverture du fichier, afficher le message d'erreur puis quitter le programme. */
perror("rapport.txt");
exit(0);
}
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Process32First(hSnapShot, &pe))
{
do
fprintf(f_rapport, "%-20s (pid = %4lu)\n", pe.szExeFile, pe.th32ProcessID);
while (Process32Next(hSnapShot, &pe));
}
/* Fermeture du fichier. */
fclose(f_rapport);
CloseHandle(hSnapShot);
return 0;
} |