Monitor process functions (API scan process ing table)

Source: Internet
Author: User
Int mywatch (char * thread_name) {processentry32 pe32; char * mychar; bool bstart = true; handle hprocesssnap; while (1) {pe32.dwsize = sizeof (pe32); hprocesssnap = :: createconlhelp32snapshot (th32cs_snapprocess, 0); If (hprocesssnap = invalid_handle_value) {printf ("createconlhelp32snapshot" Call failed! \ N "); Return-1 ;}// traverses the process snapshot. The information of each process is displayed in turn bstart = true; bool bmore =: process32first (hprocesssnap, & pe32); While (bmore) {uses_conversion; // enable the macro command mark mychar = w2a (pe32.szexefile); If (0 = strcmp (thread_name, mychar) // compare whether your process name is the same, determine whether the process is starting {printf ("your program is running! "); Bstart = false; break;} // printf (" process name: % s \ n ", w2a (pe32.szexefile); // printf (" process ID: % u \ n ", pe32.th32processid); bmore =: process32next (hprocesssnap, & pe32);} If (bstart) {ShellExecute (0, _ T ("open"), _ T ("D: \ result.txt"), null, null, sw_shownormal); // start the EXE file you want, D: \ result.txt is my own test} Sleep (5000); // monitor once every 5 seconds} // clear the snapshot object: closehandle (hprocesssnap); Return 0 ;}

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.