Process (WINAPI), traversing and finding tree-like process information to implement control system processes

Source: Internet
Author: User

#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,&AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.