`

taskkill 终止进程的简单实现(源代码)

阅读更多

更多精彩内容请访问我的博客:http://yysource.sourceforge.net

 

#include <STDIO.H>
#include <windows.h>

int main(int argc, char * argv[])
{
	HANDLE	hProcess;
	int		iProcessId, ret;

	if (argc != 2) {
		fprintf(stderr, "notice: please specified a process ID!\n");
		return 0;
	}

	iProcessId = atoi(argv[1]);
	hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, iProcessId);
	if (INVALID_HANDLE_VALUE == hProcess) {
		fprintf(stderr, "Error: Can not open specified process!\n");
		fprintf(stderr, "Error code: %d\n", GetLastError());
		return 0;
	}
	
	ret = TerminateProcess(hProcess, 0);
	
	if (ret == FALSE) {
		printf("Error: Can not terminate specified process!\n");
		printf("Error code: %d\n", GetLastError());
	}
	CloseHandle (hProcess);
	return 0;
}
0
4
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics