#include
#include
#include
#include
int killProc(char * processname)
{
HANDLE hSnapshot;
int flag;
int eqflag=0;
long int pid=-1;
hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
PROCESSENTRY32* processInfo=new PROCESSENTRY32;
processInfo->dwSize=sizeof(PROCESSENTRY32);
flag=Process32First(hSnapshot,processInfo);
while(flag != 0)
{
eqflag = 0;
for(int j=0; processInfo->szExeFile[j]!='\0'; j++)
{
if(processInfo->szExeFile[j]!=processname[j])
{
eqflag=1;
}
}
//printf("%d\n",eqflag);
if(eqflag == 0)
{
pid=processInfo->th32ProcessID;
}
flag=Process32Next(hSnapshot,processInfo);
}
CloseHandle(hSnapshot);
if (processInfo != NULL)
{
delete processInfo;
}
processInfo = NULL;
//printf("%d",pid);
if(pid==-1)
{
return 0;
}
//HANDLE hProcess=OpenProcess(PROCESS_ALL_ACCESS,TRUE,pid);
HANDLE hProcess=OpenProcess(PROCESS_TERMINATE, FALSE, pid);
//printf("%d",hProcess);
//TerminateProcess(hProcess,0);
if (TerminateProcess(hProcess,0))
{
return 1;
}
else
{
return 0;
}
}
阅读(1295) | 评论(0) | 转发(0) |