编程语言
首页 > 编程语言> > 让任何程序“停止运行”的程序

让任何程序“停止运行”的程序

作者:互联网

原理:让目标进程执行内存地址0,发生内存访问冲突

#include <cstdio>
#include <Windows.h>
using namespace std;

int main(int argc, char* argv[]) {
	if (argc < 2) {
		printf("%s PID\n", argv[0]);
		return 1;
	}
	HANDLE p = OpenProcess(PROCESS_ALL_ACCESS, 0, atol(argv[1]));
	if (!p) {
		fprintf(stderr, "Cannot open process % s", argv[1]);
		return 1;
	}
	HANDLE hTh = CreateRemoteThread(p, 0, 0, 0, 0, 0, 0);
	if (!hTh) { 
		fprintf(stderr, "CreateRemoteThread(%p,0,0,0,0,0,0) failed,GetLastError() == %d", 
			p, GetLastError());
		return 1; 
	}
	CloseHandle(hTh);
	return 0;
}

效果:

标签:GetLastError,return,int,程序,argv,hTh,停止,fprintf,运行
来源: https://blog.csdn.net/shc0743/article/details/118266859