#include <tlhelp32.h>//retrieval system all process void ShowAll () {PROCESSENTRY32 pe32 = {0};p e32.dwsize = sizeof (PE32);//lookup process handle hpprocess = CreateToolhelp32Snapshot (th32cs_snapprocess, 0);//createtoolhelp32snapshot Create snapshot bool bmore = Process32First (HPPROCESS,&PE32);//Find while (bmore) {printf ("%-25s%d\n", Pe32.szexefile, PE32.TH32PARENTPROCESSID); Bmore=process32next (hpprocess, &pe32);}} Close void close by process name (char *name) {PROCESSENTRY32 pe32 = {0};//process Snapshot pe32.dwsize = sizeof (PE32);//Set body size handle hpprocess = CreateToolhelp32Snapshot (th32cs_snapprocess, 0); BOOL bmore = Process32First (hpprocess, &pe32), while (bmore) {printf ("%s%d\n", Pe32.szexefile, Pe32.th32parentproce SsID), if (!strcmp ("FsCapture.exe", Pe32.szexefile)) {puts ("\n\nfind, the process exists! "); HANDLE Hpro = OpenProcess (process_all_access, FALSE, PE32.TH32PROCESSID);//Open Process TerminateProcess (Hpro, 0);//end thread note here} Bmore = Process32Next (hpprocess, &pe32);} printf ("\ n does not exist for this process!\n");} disable void Closebyid (unsigned long ID) by process number {PROCESSENTRY32 PE32 = {0};//process Snapshot pe32.dwsize = sizeof (PE32);//Set body size handle hpprocess = CreateToolhelp32Snapshot (th32cs_snapprocess, 0); BOOL bmore = Process32First (hpprocess, &pe32);//Find All processes while (bmore) {if (Id==pe32.th32processid) {puts ("find") ; HANDLE Hpro = OpenProcess (process_all_access, FALSE, PE32.TH32PARENTPROCESSID);//Open Process TerminateProcess (Hpro, 0);} Bmore = Process32Next (hpprocess, &pe32);}} void Main () {printf ("process name \t\t\t process number \ n"); ShowAll (); Close ("FsCapture.exe");//End process by process name Closebyid (4356);// Pass process number to end process GetChar ();}
Process (WINAPI), traversing and finding tree-like process information to implement control system processes