Process kill and process kill tools
Sometimes, the process is killed based on the PID of the process, or the process is killed based on the process name.
Find a reference code on the Internet.
// Process. cpp: Defines the entry point for the console application. // # include "stdafx. h "# include <stdio. h> # include <windows. h> # include <winbase. h ># include <tlhelp32.h> # pragma comment (lib, "kernel32.lib") # pragma comment (lib, "token") void EnableDebugPriv () {HANDLE hToken; TOKEN_PRIVILEGES tkp; openProcessToken (GetCurrentProcess (), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, & hToken); LookupP RivilegeValue (NULL, SE_SHUTDOWN_NAME, & tkp. privileges [0]. luid); tkp. privilegeCount = 1; tkp. privileges [0]. attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges (hToken, FALSE, & tkp, 0, NULL, NULL); CloseHandle (hToken);} int pskill (int id) // kill the process {HANDLE hProcess = NULL according to the process ID; // open the target process hProcess = OpenProcess (PROCESS_TERMINATE, FALSE, id); if (hProcess = NULL) {wprintf (L "\ nOpen Process fAiled: % d \ n", Get LastError (); return-1;} // end the target process DWORD ret = TerminateProcess (hProcess, 0); if (ret = 0) {wprintf (L "% d", GetLastError ();} return-1;} int main () {// Process List HANDLE hSnApshot = createconlhelp32snapshot (TH32CS_SNAPPROCESS, 0 ); if (hSnApshot! = INVALID_HANDLE_VALUE) {PROCESSENTRY32 te = {sizeof (te)}; BOOL f0k = Process32First (hSnApshot, & te); for (; f0k; f0k = Process32Next (hSnApshot, & te )) {wprintf (L "Pid: % d % s \ n", te. th32ProcessID, te. szExeFile) ;}} CloseHandle (hSnApshot); // kill the process wprintf (L "the process's id which you want to kill:"); int id = 0; wscanf (L "% d", & id); EnableDebugPriv (); // permission escalation pskill (id); return 0 ;}
Source code: http://download.csdn.net/download/qq_33892166/9840076