#include <tlhelp32.h>
BOOL CXXXX::KillProcess(LPCTSTR lp) { HANDLE SnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); if(SnapShot == NULL) { // MessageBox("检测当前进程失败!"); return FALSE; } SHFILEINFO shSmall;
CString str,prcnum; PROCESSENTRY32 ProcessInfo;//声明进程信息变量 ProcessInfo.dwSize = sizeof(ProcessInfo);//设置ProcessInfo的大小 //返回系统中第一个进程的信息 BOOL Status = Process32First(SnapShot,&ProcessInfo); int m_nProcess = 0,num = 0; while(Status) { m_nProcess++; num++; //ZeroMemory(&shSmall,sizeof(shSmall)); //获取进程文件信息 SHGetFileInfo(ProcessInfo.szExeFile,0,&shSmall,sizeof(shSmall), SHGFI_ICON|SHGFI_SMALLICON); CString strtmp = ProcessInfo.szExeFile; //删除指定进程 if (strtmp == lp) { HANDLE hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE,ProcessInfo.th32ProcessID); if(::TerminateProcess(hProcess,1)) { //成功杀死进程 return TRUE; } } Status=Process32Next(SnapShot,&ProcessInfo); } return FALSE; } |