#include<stdio.h>
#include <Windows.h>
#include<tlhelp32.h>
#include<string.h>
extern void DirectoryString(DWORD dwIndex);
/遍历进程寻找指定进程/
void LookForSpecialProcess()
{
HANDLE hMutex; //定义一个互斥体变量
hMutex = CreateMutex(NULL,FALSE,“KyUffThOkYwRRtgPP”);
if(!hMutex||GetLastError()==183)//表示目前进程中已经存在该互斥体
{
ReleaseMutex(hMutex);//如果系统中存在,则释放该互斥体
}
HANDLE hproc;
PROCESSENTRY32 currentProcess; //存放快照进程信息的一个结构体
currentProcess.dwSize = sizeof(currentProcess); //在使用这个结构之前,先设置它的大小
HANDLE hProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);//给系统内的所有进程拍一个快照
if (hProcess == INVALID_HANDLE_VALUE)
{
printf(“SomeThingWrong”);
}
bool bMore=Process32First(hProcess,¤tProcess); //获取第一个进程信息
while(bMore)
{
if(!strcmp(currentProcess.szExeFile,“notepad.exe”))//查找目标notepad.exe进程,如果找到,杀死该进程
{
hproc=OpenProcess(PROCESS_ALL_ACCESS, FALSE, currentProcess.th32ProcessID);//获取进程句柄
TerminateProcess(hproc,NULL);//结束进程
}
bMore=Process32Next(hProcess,¤tProcess); //遍历下一个
}
CloseHandle(hProcess); //清除hProcess句柄
}
遍历系统进程,结束指定进程
最新推荐文章于 2022-05-12 21:04:36 发布