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 ;}