#include <iostream> #include <string> #include <map> #include <windows.h> #include <TlHelp32.h> using namespace std; int FindPID(string ProcessName) { PROCESSENTRY32 pe32; pe32.dwSize = sizeof(pe32); HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(hProcessSnap == INVALID_HANDLE_VALUE) { cout << "CreateToolhelp32Snapshot Error!" << endl;; return false; } BOOL bResult =Process32First(hProcessSnap, &pe32); int num(0); while(bResult) { if(pe32.szExeFile==ProcessName) { return pe32.th32ProcessID; } bResult = Process32Next(hProcessSnap,&pe32); } CloseHandle(hProcessSnap); return -1; } int main() { cout<<FindPID("game.exe"); return 0; }