15,466
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <windows.h>
#include <string.h>
#include <tlhelp32.h>
#pragma comment(linker, "/subsystem:\"Windows\" /entry:\"mainCRTStartup\"")
void KillProcess(DWORD Pid)
{
HANDLE hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,Pid);
int a=TerminateProcess(hProcess,0);
}
void scan()
{
char *p="War3.exe";
PROCESSENTRY32 pe32;
pe32.dwSize=sizeof(pe32);
HANDLE hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
BOOL bProcess=Process32First(hProcessSnap,&pe32);
while(bProcess)
{
if(*pe32.szExeFile==*p){KillProcess(pe32.th32ProcessID);break;}
bProcess=Process32Next(hProcessSnap,&pe32);
}
CloseHandle(hProcessSnap);
}
int main()
{
while(TRUE)
{
scan();
}
return 0;
}
char szFilters[]=
"exe Files (*.exe)|*.exe|All Files (*.*)|*.*||";
CFileDialog fileDlg (TRUE, "exe", "*.exe",
OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);
fileDlg.m_ofn.lStructSize = 88;
if( fileDlg.DoModal ()==IDOK )
{
SetAppRun(fileDlg.GetFileName());
}void SetAppRun(LPCTSTR lpAppName, BOOL bRun)
{
HKEY hKey;
LONG lRet;
DWORD dw1;
CString strSubKey;
strSubKey.Format("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\%s",
lpAppName);
if(!bRun)
{
lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE,strSubKey,0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,&dw1);
LPCTSTR lpNoRun = "DisabledRun";
RegSetValueEx(hKey,"Debugger",0,REG_SZ,(CONST BYTE *)lpNoRun,strlen(lpNoRun)+1);
RegCloseKey(hKey);
}
else
{
RegDeleteKey(HKEY_LOCAL_MACHINE,strSubKey);
}
MessageBox("设置完成!");
}