吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 8576|回复: 28
收起左侧

[原创工具] 【Windows】【cmd】进程黑名单工具(基于WinAPI和C++)

  [复制链接]
~零度 发表于 2018-4-21 15:53
本帖最后由 ~零度 于 2018-4-21 15:57 编辑

楼主在安装QQ之后发现后台总是存在名为“QQProtect.exe”的进程,并且修改应用程序服务的方式时提示拒绝访问,而且不知为何在自己的电脑上无法使用“tasklist、taskkill”等命令,所以基于Windows API和C++编写了这个自动检测进程和杀死进程的命令行工具。您可以将“killprocess /e QQProtect”添加为开机启动来实现阻止黑名单程序的运行。
使用方法(英文):
Snipaste_2018-04-21_15-55-21.png
中文翻译:
KillProcess  版本: 1.0  构建日期: 2018 / 4 / 21  作者:~零度( @52PoJiE )
用法:
killprocess [ / E EXE文件名] [ /I 两次检测的时间间隔] [ /M 最大运行时间] [ /N 最大杀进程次数]
/E 指定进程名称。这是必要的参数。
/I 指定检测之间的间隔(以秒为单位,默认值: 3 )。如果此值小于或等于0,程序将连续检测(不推荐)。
/M 指定此程序的最长时间(以秒为单位,默认值: 30 )。如果此值小于或等于0,程序将连续运行。
/N 指定成功终止进程的最大次数(默认值: 1 )。如果此值小于或等于0,则次数将是无限的。
您可以将此程序添加到PATH环境变量中。
不带参数运行程序可以查看帮助信息,不区分大小写,后缀".exe"可写可不写。
killprocess.rar (156.7 KB, 下载次数: 90)
如果有什么问题欢迎大家和我讨论!编写程序不易,如果您觉得好用,望给个评分。开发平台:Win7 x86_64
以下是源代码:
[C++] 纯文本查看 复制代码
#include <windows.h>
#include <process.h>
#include <Tlhelp32.h>
#include <winbase.h>
#include <string.h>
#include <iostream>
#include <cstdio>
#include <ctime>
using namespace std;
int success(0);
bool killProcess(const char *filename)
{
    HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
    PROCESSENTRY32 pEntry;
    pEntry.dwSize = sizeof (pEntry);
    BOOL hRes = Process32First(hSnapShot, &pEntry);
    bool match=false;
    int i;
    while (hRes)
    {
        for(i=0; filename[i]!='\0'&&pEntry.szExeFile[i]!='\0'; ++i)
            if(filename[i]!=pEntry.szExeFile[i]&&(filename[i]-pEntry.szExeFile[i])!=32&&(pEntry.szExeFile[i]-filename[i])!=32)
            {
                match=false;
                break;
            }
            else
            {
                match=true;
            }
        if(match&&pEntry.szExeFile[i]!='\0')
        {
            if(pEntry.szExeFile[i]!='.'||(pEntry.szExeFile[i+1]!='e'&&pEntry.szExeFile[i+1]!='E')||(pEntry.szExeFile[i+2]!='x'&&pEntry.szExeFile[i+2]!='X')||(pEntry.szExeFile[i+3]!='e'&&pEntry.szExeFile[i+3]!='E')||pEntry.szExeFile[i+4]!='\0')
            {
                match=false;
            }
        }
        if (match)
        {

            HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0,(DWORD) pEntry.th32ProcessID);
            if (hProcess != NULL)
            {
                TerminateProcess(hProcess, 9);
                ++success;
                CloseHandle(hProcess);
                CloseHandle(hSnapShot);
                return true;
            }
        }
        hRes = Process32Next(hSnapShot, &pEntry);
    }
    CloseHandle(hSnapShot);
    return false;
}
typedef struct _MyData//Parameter structure to the child thread
{
    char *EXEFileName;
    int TimeInterval,NumofTimes;
} MYDATA, *PMYDATA;
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
    PMYDATA pData;
    pData=(PMYDATA)lpParam;
    int TimeInterval=pData->TimeInterval,NumofTimes=pData->NumofTimes;
    char *EXEFileName=pData->EXEFileName;
    for(;;)
    {
        killProcess(EXEFileName);
        if(NumofTimes>0&&success>=NumofTimes)return 0;
        if(TimeInterval>0)Sleep(TimeInterval*CLOCKS_PER_SEC);
    }
    return 0;
}
int main(int argc,char *argv[])
{
    int TimeInterval(3),MaximumTime(30),NumberofTimes(1);
    char *EXEFileName(NULL);
    if(argc<=1)
    {
        cout<<"KillProcess Version:1.0 Build Date:2018/4/21 Author:~零度(@52pojie)\n"
            <<"Usage:\n\n killprocess [/E EXE File Name] [/I Time Interval] [/M Maximum Time] [/N Number of Times]\n"
            <<"\n  /E Specifies the process name. This is a necessary parameter.\n"
            <<"\n  /I Specifies the interval between detections(in seconds,default:3). If this value is less than or equal to 0, the program will detect continuously(not recommended).\n"
            <<"\n  /M Specifies the maximum time for this program(in seconds,default:30). If this value is less than or equal to 0, the program will run continuously.\n"
            <<"\n  /N Specifies the maximum number of successfully terminating the process(default:1). If this value is less than or equal to 0, the number of times will be infinite.\n"
            <<"\n\n  You can add this program to your PATH environmental variable.\n";
        return 0;
    }
    else
    {
        for(int i=1; i<argc; i+=2)
        {
            if(argv[i][0]=='/')
                switch(argv[i][1])
                {
                case 'E':
                case 'e':
                    EXEFileName=argv[i+1];
                    break;
                case 'I':
                case 'i':
                    sscanf(argv[i+1],"%d",&TimeInterval);
                    break;
                case 'M':
                case 'm':
                    sscanf(argv[i+1],"%d",&MaximumTime);
                    break;
                case 'N':
                case 'n':
                    sscanf(argv[i+1],"%d",&NumberofTimes);
                    break;
                default:
                    cout<<"Error: Unknown Parameters!\nYou can run this program without parameters to see the usage.\n";
                    return -1;
                }
            else
            {
                cout<<"Error: Unknown Parameters!\nYou can run this program without parameters to see the usage.\n";
                return -1;
            }
        }
    }
    if(EXEFileName==NULL)
    {
        cout<<"Error: [/E EXEFileName] is a necessary parameter.You can run this program without parameters to see the usage.\n";
        return -1;
    }
    else
    {
        if(MaximumTime<=0)
            for(;;)
            {
                killProcess(argv[1]);
                if(NumberofTimes>0&&success>=NumberofTimes)
                    return success;
                if(TimeInterval>0)Sleep(TimeInterval*CLOCKS_PER_SEC);
            }
        else
        {
            HANDLE hThread;
            DWORD ThreadId;
            PMYDATA pData=(PMYDATA)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(MYDATA));
            pData->EXEFileName=EXEFileName;
            pData->TimeInterval=TimeInterval;
            pData->NumofTimes=NumberofTimes;
            hThread=CreateThread(NULL,0,ThreadProc,pData,0,&ThreadId);
            //Create a child thread to compute DFT directly
            if(WaitForMultipleObjects(1,&hThread, TRUE, MaximumTime*CLOCKS_PER_SEC))
            {
                TerminateThread(hThread,-1);
            }
            //wait for the child thread to return, if time exceeded then kill the child thread
            CloseHandle(hThread);
        }
        return success;
    }
}


免费评分

参与人数 12吾爱币 +17 热心值 +10 收起 理由
Gzsod + 1 + 1 热心回复!
siwuye + 1 + 1 谢谢@Thanks!
szqever + 1 + 1 谢谢@Thanks!
DDK + 1 + 1 谢谢@Thanks!
qaz10533 + 1 + 1 我很赞同!
rockingus! + 1 谢谢@Thanks!
harygary + 1 + 1 谢谢@Thanks!
云在天 + 6 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
152a + 1 + 1 谢谢@Thanks!
_小白 + 1 + 1 我很赞同!
15237633705 + 1 + 1 热心回复!
Ph3C + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

152a 发表于 2018-4-21 20:42
本帖最后由 152a 于 2018-4-21 21:42 编辑

这个软件在使用的时候必须写成批处理
killprocess /e QQProtect
killprocess /e QQProtect
killprocess /e QQProtect
killprocess /e QQProtect
killprocess /e QQProtect
killprocess /e QQProtect
killprocess /e QQProtect
killprocess /e QQProtect
killprocess /e QQProtect
killprocess /e QQProtect
类似的格式

用vb语句循环一下就能解决问题

Dim objws
Set objws=WScript.CreateObject("wscript.shell")
while true
   wscript.sleep 5000
   objws.RUN "2.vbs"
wend
test.vbs负责循环2.vbs


Set ws = CreateObject("Wscript.Shell")
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'notepad.exe'")
If colProcessList.Count>0 Then
ws.run "cmd /c 1.cmd",vbhide
Else
end if

2.vbs负责在程序运行的时候执行1.cmd

start D:\进程终结者\7.exe /e notepad

1.cmd则负责结束进程

3个文件2.vbs 1.cmd test.vbs必须放在同一目录。



Ph3C 发表于 2018-4-21 16:31
吾爱luo 发表于 2018-4-21 16:37
15237633705 发表于 2018-4-21 16:38
谢谢分享 我去试试看
juiceV5 发表于 2018-4-21 17:10
使用说明其实应该按多个实例应用来写比较适合如我这样的菜鸟
一目了然
juiceV5 发表于 2018-4-21 17:11
我推荐pchunter工具,不错
相逢何必曾相识! 发表于 2018-4-21 17:27 来自手机
高科技来了
sumile 发表于 2018-4-21 18:04
QQProtect停了QQ也会闪退吧。
 楼主| ~零度 发表于 2018-4-21 18:39
本帖最后由 ~零度 于 2018-4-21 18:43 编辑
sumile 发表于 2018-4-21 18:04
QQProtect停了QQ也会闪退吧。
写这个的主要目的是代替taskkill,QQProtect在使用QQ的时候必须打开,不然QQ启动不了,把它杀掉的原因是我很少用到QQ,但是QQProtect是开机自启动的。
umbrella_red 发表于 2018-4-21 20:17
我可以用它把小娜搞掉吗
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 提醒:禁止复制他人回复等『恶意灌水』行为,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-3-29 13:58

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表