开发学院软件开发VC VC++杀进程的程序 阅读

VC++杀进程的程序

 2008-09-23 19:27:16 来源:WEB开发网   
核心提示:include"stdafx.h"#include"LCNew.h"#include<tlhelp32.h>#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#en

include"stdafx.h"
  
#include"LCNew.h"
  
#include <tlhelp32.h>  
  
#ifdef_DEBUG
  
#definenewDEBUG_NEW
  
#undefTHIS_FILE
  
staticcharTHIS_FILE[]=__FILE__;
  
#endif
  
/////////////////////////////////////////////////////////////////////////////
  
//Theoneandonlyapplicationobject
  
CWinApptheApp;
  
usingnamespacestd;
  
//OA系统进程处理程序
  
voidKillProgram(LPCSTR ExeName)  
  
{  
  
 LPCSTR File;  
  
 HANDLE hProcessSnap;  
  
 PROCESSENTRY32 pe32;  
  
 if(!ExeName||!ExeName[0]) return;  
  
 File=strrchr(ExeName,'');  
  
 if(File!=0)ExeName=File+1;  
  
 hProcessSnap=CreateToolhelp32Snapshot(  
  
         TH32CS_SNAPPROCESS,0);  
  
         if(hProcessSnap==(HANDLE)-1) return;  
  
         memset(&pe32,0,sizeof(pe32));  
  
         pe32.dwSize=sizeof(PROCESSENTRY32);  
  
         if(Process32First(hProcessSnap,&pe32))  
  
         {  
  
          do 
  
          {  
  
             File=strrchr(pe32.szExeFile,'');  
  
             File=File?File+1:pe32.szExeFile;  
  
             if(strcmpi(File,ExeName)==0)  
  
             {  
  
                 TerminateProcess(OpenProcess(  
  
                     PROCESS_ALL_ACCESS,0,pe32  
  
                     .th32ProcessID),0);  
  
                 break;  
  
             }  
  
          }  
  
         while(Process32Next(hProcessSnap,&pe32));  
  
         }  
  
 CloseHandle(hProcessSnap);  
  
}
  
int_tmain(intargc,TCHAR*argv[],TCHAR*envp[])
  
{
  
  intnRetCode=0;
  
  if(!AfxWinInit(::GetModuleHandle(NULL),NULL,::GetCommandLine(),0))
  
  {
  
    cerr<<_T("FatalError:MFCinitializationfailed")<<endl;
  
    nRetCode=1;
  
  }
  
  else
  
  {
  
    //CStringstrHello;
  
    //strHello.LoadString(IDS_HELLO);
  
    //cout<<(LPCTSTR)strHello<<endl;
  
    cout<<"Kill ProccesA.exe"<<endl;
  
    KillProgram("ProccesA.exe");
  
  }
  
  returnnRetCode;
  
}

Tags:VC 进程 程序

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接