Process Cleaner

  1 #include <cstdio>
  2 #include <windows.h>
  3 #include <tlhelp32.h>
  4
  5 using namespace std;
  6
  7 const int MAX = 10;
  8
  9 char SysProcList[MAX][MAX_PATH] = {
 10     "[system process]",
 11     "system",
 12     "smss.exe",
 13     "csrss.exe",
 14     "winlogon.exe",
 15     "services.exe",
 16     "lsass.exe",
 17     "svchost.exe",
 18     "explorer.exe",
 19     "ctfmon.exe"
 20 };
 21
 22 bool CheckSysProcList(char *lpText);
 23 void PrintfNormal(char *lpText);
 24 void PrintfSucceed(char *lpText);
 25 void PrintfError(char *lpText);
 26
 27 int main()
 28 {
 29     SetConsoleTitleA("Process Cleaner v0.1 Made By gwsbhqt");
 30
 31     HANDLE hToken;
 32     OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken);
 33
 34     LUID luid = {};
 35     LookupPrivilegeValueA(NULL, "SeDebugPrivilege", &luid);
 36
 37     TOKEN_PRIVILEGES tp = {};
 38     tp.PrivilegeCount = 1;
 39     tp.Privileges[0].Luid = luid;
 40     tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
 41     if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL))
 42     {
 43         PrintfError("ERROR_01\n");
 44         Sleep(5000);
 45         return 0;
 46     }
 47
 48     HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
 49     if (INVALID_HANDLE_VALUE == hSnapshot)
 50     {
 51         PrintfError("ERROR_02\n");
 52         Sleep(5000);
 53         return 0;
 54     }
 55
 56     tagPROCESSENTRY32 pe32;
 57     pe32.dwFlags = sizeof(pe32);
 58
 59     BOOL ret = Process32First(hSnapshot, &pe32);
 60     while (ret)
 61     {
 62         Sleep(400);
 63
 64         if (pe32.th32ProcessID == GetCurrentProcessId())
 65         {
 66             ret = Process32Next(hSnapshot, &pe32);
 67             continue;
 68         }
 69
 70         bool isSysProc = CheckSysProcList(strlwr(pe32.szExeFile));
 71
 72         char str[MAX_PATH];
 73         sprintf(str, "%d %s %s", pe32.th32ProcessID, strlwr(pe32.szExeFile), isSysProc ? "ignored -\n" : "");
 74         PrintfNormal(str);
 75
 76         if (!isSysProc)
 77         {
 78             BOOL tpret = TerminateProcess(OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID), NULL);
 79             sprintf(str, "shutdown %s\n", tpret ? "succeed √" : "faild ×");
 80
 81             if (tpret)
 82                 PrintfSucceed(str);
 83             else
 84                 PrintfError(str);
 85         }
 86
 87         ret = Process32Next(hSnapshot, &pe32);
 88     }
 89
 90     PrintfNormal("\nProcess Clean Finish...\n");
 91     Sleep(5000);
 92     return 0;
 93 }
 94
 95 bool CheckSysProcList(char *lpText)
 96 {
 97     for (int i = 0; i < MAX; i++)
 98         if (0 == strcmp(lpText, SysProcList[i]))
 99             return true;
100
101     return false;
102 }
103
104 void PrintfNormal(char *lpText)
105 {
106     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
107     printf("%s", lpText);
108 }
109
110 void PrintfSucceed(char *lpText)
111 {
112     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);
113     printf("%s", lpText);
114 }
115
116 void PrintfError(char *lpText)
117 {
118     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
119     printf("%s", lpText);
120 }

main.cpp

时间: 2024-12-24 11:51:17

Process Cleaner的相关文章

Erlang 设计原则 process port io

Erlang原理 (转载自ITEYE cryolite博客 ps:精彩)by Robert Virding This is a description of some of the basic properties and features of Erlang and an attempt to describe the rationale behind them. Erlang grew as we better understood the original problem we were

Process Kill Technology &amp;&amp; Process Protection Against In Linux

目录 0. 引言 1. Kill Process By Kill Command 2. Kill Process By Resource Limits 3. Kill Process By Code Injection Into Running Process Via GDB 4. Kill Process By Using Cross Process Virtual Memory Modify 5. Kill Process By Using ptrace To Inject .so 6. P

centOS 7一个解决“network.service: control process exited, code=exited status=1”方法

今天早上2017-08-04,我打开虚拟机,使用远程工具xshell对虚拟机进行连接,我发现连接不上去,然后我ifconfig,发现找不到ens33了,就剩一个本地回环,看来是我的网络出现了问题,然后我查看我的网络状态,发现了如下情况: [[email protected] ~]# systemctl status network.service ● network.service - LSB: Bring up/down networking Loaded: loaded (/etc/rc.d

python pip fatal error in launcher unable to create process using

用pip安装一个包,不知道为啥,就报了这个错误:python pip fatal error in launcher unable to create process using “” 百度了一下,用下面的命令可以解决,搞定 python2 -m pip install XXX  另外,Python3 的pip我用python3 -m pip install --upgrade pip 搞定

MySQL 授予普通用户PROCESS权限

在MySQL中如何给普通用户授予查看所有用户线程/连接的权限,当然,默认情况下show processlist是可以查看当前用户的线程/连接的. mysql> grant process on MyDB.* to test; ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES 第一次授予这样的权限,错误原因是process权限是一个全局权限,不可以指定在某一个库上(个人测试库为MyDB),所以,把授权语句更改

ERROR &nbsp; OGG-01668 PROCESS ABENDING.

oracle ogg 出现如下报错 ERROR   OGG-01172  Discard file (/ogg/oggrm/11.2/dirdat/repa.dsc) exceeded max bytes (2000000000). ERROR   OGG-01668  PROCESS ABENDING. 可以看出repa.dsc文件达到了最大值.导致错误是文件写满,大部分情况则是表同步出错,具体的错误可以通过查看OGG错误日志中看到. 解决办法如下: 1.repa.dsc文件的最大值可以在vi

JBPM工作流(八)——流程实例(PI)Process Instance

/** * 流程实例 *    *  启动流程实例 *    *  完成任务 *    *  查询 *      *  查询流程实例 *      *  查询任务 *          *  查询正在执行的任务 *            *  查询所有的正在执行的任务 *            *  根据任务的执行人查询正在执行的任务 *            *  根据executionId查询正在执行的任务 *            *  根据piid查询正在执行的任务 *         

receive和process的过程

(一) receive最终在fuse_kern_chan.c中的fuse_kern_chan_receive函数实现,使用系统调用读取 res = read(fuse_chan_fd(ch), buf, size); 其中fuse_chan_fd(ch)就是/dev/fuse, buf和size在fuse_loop_mt.c中fuse_do_work中定义. struct fuse_buf fbuf = { .mem = w->buf, .size = w->bufsize, }; 其中的fb

out of memory kill process (java) score or a child

最近在跑大数据,发现 out of memory kill process (java) score or a child,查资料发现是操作系统linux low mem 太低,后来加大内存一样不管用,开始分析代码: 将代码中的String 字符串拼接改成StringBuilder(单线程速度比StringBuffer快) 将获取文件名称的方法file.listFiles() 改成 file.list() 将代码中的不必要的创建对象.数组开销去掉,尤其是在循环里 发现仍然有问题,通过free -