说明:
全路径只是一种方式,其他的比如通过PID等都是一个道理~
示例代码:
BOOLTerminateExe(const CString& strPath )
{
PROCESSENTRY32 pe32 = {0};
pe32.dwSize = sizeof(pe32);
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hProcessSnap == INVALID_HANDLE_VALUE) {
return FALSE;
}
HANDLE hPath = NULL ;
MODULEENTRY32 mod32 = {0};
mod32.dwSize = sizeof(MODULEENTRY32);
BOOL bResult = Process32First(hProcessSnap, &pe32);
while(bResult)
{
CString strExe = pe32.szExeFile;
if (!strExe.CompareNoCase(L"explore.exe")){
hPath = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE , pe32.th32ProcessID );
if (hPath != NULL ){
if(Module32First(hPath ,&mod32)){
CString strExePath = mod32.szExePath;
if (!strExePath.CompareNoCase(strPath)){
HANDLE hProc = ::OpenProcess( PRO