现在的位置: 首页 > 综合 > 正文

结束进程

2012年04月17日 ⁄ 综合 ⁄ 共 606字 ⁄ 字号 评论关闭
#include "StdAfx.h"

#include <stdio.h>
#include <Windows.h>
#include <Tlhelp32.h>

BOOL KillProcess(LPCTSTR lpszProcessName)
{
	PROCESSENTRY32 pe32 = {sizeof(pe32)} ;
	HANDLE hProcessShot = CreateToolhelp32Snapshot ( TH32CS_SNAPPROCESS, 0 ) ;
	if ( hProcessShot == INVALID_HANDLE_VALUE )
		return FALSE ;
	if ( Process32First ( hProcessShot, &pe32 ) )
	{
		do {

			if (!stricmp(pe32.szExeFile,lpszProcessName))
			{
				HANDLE   handle=OpenProcess(PROCESS_TERMINATE,FALSE,pe32.th32ProcessID);
				TerminateProcess(handle,0);
				CloseHandle ( hProcessShot ) ;
				return TRUE;
				
			}
		}while ( Process32Next ( hProcessShot, &pe32 ) ) ;
	}

	CloseHandle ( hProcessShot ) ;
	return FALSE;
}

void main()
{
	KillProcess("notepad.exe");
}
【上篇】
【下篇】

抱歉!评论已关闭.