通過程序名稱查詢和殺死程序
阿新 • • 發佈:2019-01-08
void KillRelatedProcess(char* cProcess) { HANDLE hSnapshot; PROCESSENTRY32 pe; hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); Process32First(hSnapshot,&pe); do { if(strcmp(pe.szExeFile,cProcess)==0) { HANDLE hProcess; hProcess=OpenProcess(PROCESS_TERMINATE,FALSE,pe.th32ProcessID); if (hProcess) { TerminateProcess(hProcess,0); } } } while(Process32Next(hSnapshot,&pe)); CloseHandle(hSnapshot); }
BOOL FindAISProcess(char* cProcess) { BOOL bRet = FALSE; HANDLE hSnapshot; PROCESSENTRY32 pe; hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); Process32First(hSnapshot,&pe); do { if(strcmp(pe.szExeFile,cProcess)==0) { bRet = TRUE; break; } } while(Process32Next(hSnapshot,&pe)); CloseHandle(hSnapshot); return bRet; }