#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");
}