#include "tlhelp32.h"
void KillExe(const char* szExeName)
{
if (szExeName == NULL)
return 0
int lsr = lstrlen(szExeName)
if (lsr == 0)
return 0
PROCESSENTRY32 my
HANDLE l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
if (((int)l) != -1)
{
my.dwSize = sizeof(my)
if (Process32First(l, &my))
{
do
{
if (lstrcmpi(szExeName, my.szExeFile + lstrlen(my.szExeFile) - lsr) == 0)
{
HANDLE hProcessHandle
hProcessHandle = OpenProcess(0x1F0FFF, true, my.th32ProcessID)
if (hProcessHandle != NULL)
{
if (TerminateProcess(hProcessHandle, 0) != NULL)
{
CloseHandle(hProcessHandle)
}
}
CloseHandle(l)
return
}
}while (Process32Next(l, &my))
}
CloseHandle(l)
}
}
调用方式
KillExe("c:\\windows\\notepad.exe")
完整或部分路径名,不区分大小写
Process[] ps = Process.GetProcesses()//获取计算机上所有进程foreach (Process p in ps)
{
if (p.ProcessName == "QQ")//判断进程名称
{
p.Kill()//停止进程
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)