#include <stdio.h>
#include <string.h>
#include <locale.h>
#include <mbstring.h>
#include <stdlib.h>
#include <windows.h>
#include <tchar.h>
#include <shlwapi.h>
#include <iostream>
#include <Tlhelp32.h>
DWORD GetProcessIdFromName(LPCTSTR name)
{
PROCESSENTRY32 pe;
DWORD id = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
pe.dwSize = sizeof(PROCESSENTRY32);
if( !Process32First(hSnapshot,&pe) )
return 0;
do
{
pe.dwSize = sizeof(PROCESSENTRY32);
if( Process32Next(hSnapshot,&pe)==FALSE )
break;
if(lstrcmp(pe.szExeFile,name) == 0)
{
id = pe.th32ProcessID;
break;
}
} while(1);
CloseHandle(hSnapshot);
return id;
}
int _tmain(int argc, TCHAR *argv[],char *envp[] ){
DWORD processId = GetProcessIdFromName(_T("QQ.exe"));
//根据进程名获取进程ID
HANDLE myhandle = OpenProcess(PROCESS_ALL_ACCESS,TRUE,processId);
//根据进程ID获取进程句柄
::TerminateProcess(myhandle,0);
//终止进程
}