Joke Collection Website - Joke collection - How mfc exits the process completely

How mfc exits the process completely

Bull? KillProcessFromName(CString? strProcessName)?

{?

//Create process snapshots (TH32CS_SNAPPROCESS means to create snapshots of all processes)?

Handle? hSnapShot? =? createtoolhelp 32 snapshot(th 32 cs _ snap process,0); ?

//PROCESSENTRY32 What is the structure of the process snapshot?

PROCESSENTRY32? PE; ?

//What initialization operation must be done before using Process32First to get the first snapshot after instantiation?

pe.dwSize? =? sizeof(process entry 32); ?

//The following IF effects are the same:?

//if(hProcessSnap? ==? INVALID_HANDLE_VALUE) Invalid handle?

If (! process 32 first(hSnapShot & amp; pe))?

{?

Return? Fake; ?

}?

//Convert a string to lowercase?

strProcessName。 make lower(); ?

//If the handle is valid? And then continue to get the next handle and loop on?

What time? (process 32 next(hSnapShot & amp; pe))?

{?

//pe.szExeFile Get the executable file name of the current process?

CString? scTmp? =? pe.szExeFile?

//Change all English letters of the executable file name to lowercase?

scTmp。 make lower(); ?

//Compare whether the executable file name of the current process and the passed-in file name are the same?

//Similarly, Compare returns 0?

If (! scTmp。 Compare(strProcessName))?

{?

//Get the PID of the snapshot process (that is, the PID in the task manager)?

DWORD? dwProcessID? =? PE . th 32 processid; ?

Handle? hProcess? =? * open PROCESS(PROCESS _ termin ate,FALSE,dwProcessID); ?

* termin ate process(h process,0); ?

close handle(h process); ?

Return? True; ?

}?

scTmp。 ReleaseBuffer()。 ?

}?

strProcessName。 ReleaseBuffer()。 ?

Return? Fake; ?

}