结束进程

#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");
}
posted @ 2009-10-21 00:22  Fan Zhang  阅读(165)  评论(0)    收藏  举报