//安全系数并不是很高

// MyKiller.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include <windows.h>

#include <TLHELP32.H>

void GetPorcess()

{

PROCESSENTRY32 pe32;

pe32.dwSize=sizeof(pe32);

HANDLE hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);

if (hProcessSnap==INVALID_HANDLE_VALUE)

{

printf("CreateToolhelp32Snapshot调用失败!\n");

return;

}

BOOL bMore=Process32First(hProcessSnap,&pe32);

while (bMore)

{

printf("进程名称: %s \n",pe32.szExeFile);

printf("进程ID号: %d \n",pe32.th32ProcessID);

bMore=Process32Next(hProcessSnap,&pe32);

}

CloseHandle(hProcessSnap);

}

void killer()

{

printf("请输入ID号:\n");

int ID;

scanf("%d",&ID);

HANDLE target = OpenProcess(PROCESS_ALL_ACCESS,FALSE,ID);

if (target!=NULL)

TerminateProcess(target,1);

CloseHandle(target);

}

int main(int argc, char* argv[])

{

GetPorcess();

killer();

return 0;

}