VC++杀进程的程序
2008-09-23 19:27:16 来源:WEB开发网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;
}
更多精彩
赞助商链接