根据进程名杀死进程

#include <afx.h>
#include <Tlhelp32.h>

 

int killpro(CString a)
{
 PROCESSENTRY32 pe32;
 pe32.dwSize =sizeof(pe32);
 HANDLE hpro=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
 
 if(hpro==INVALID_HANDLE_VALUE )
 {  
  return 0;
 }
 BOOL nowrun=Process32First(hpro,&pe32);
 while(nowrun)
 {
  if(pe32.szExeFile ==a)
  {
   DWORD proid=pe32.th32ProcessID;
   HANDLE hprocess=::OpenProcess(PROCESS_ALL_ACCESS,FALSE,proid);
   if(hprocess!=NULL)
   {
    ::TerminateProcess(hprocess,0);
    ::CloseHandle(hprocess);
   }
  }
  nowrun=::Process32Next(hpro,&pe32);
 }
}

posted @ 2012-12-06 15:28  废弃账号  阅读(144)  评论(0编辑  收藏  举报