//记得包含头文件
#include "tlhelp32.h"
void KillProgram(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);
}
如果是在VS编译器中要更改字符集的类型,具体方法是,右击项目->项目属性页->配置属性->常规->字符集;更改为“使用多字节字符集”。