#include "stdafx.h"
#include <string.h>
#include <iostream.h>
#include<stdio.h>
#include <stdlib.h>
#include <
windows.h>
#pragma comment(lib,"Kernel32.lib")
#include <WinBase.h>
int main(int argc, char* argv[])
{
BOOL res=FALSE;
HANDLE hjob=CreateJobObject(NULL,TEXT("killrav")); //建立job对象,命名为killrav
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,0,atoi(argv[1]));//打开进程
if (hProcess==NULL) //打开失败
{
printf("\t\t OpenProcessError!please Look up your Privilege first ^_^\n");
return 0;
}
AssignProcessToJobObject(hjob,hProcess);//将进程和对象关联起来
res=TerminateJobObject(hjob,0);//结束对象
if (res==FALSE) printf("\t\t Sorry ,can't kill the process you want \n");
else
printf("\t\t Ok ,Now you can check if the process still exists \n");
return 0;
}
代码很简单,我已经做了比较详细的注释,不懂的朋友可以去查msdn,上网搜索也可以,顺便说下stdafx.h这个头文件的第一行要加一句 “#define _WIN32_WINNT 0x0500”的宏定义,否则程序会编译失败,程序在