Winfoson így néz ki:#include <windows.h>
#include <tlhelp32.h>
int getPID(wchar_t* name)
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE)
{
while (Process32Next(snapshot, &entry) == TRUE)
{
if (wcscmp(entry.szExeFile, name) == 0)
{
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID);
DWORD processId = GetProcessId(hProcess);
CloseHandle(hProcess);
return processId;
}
}
}
CloseHandle(snapshot);
return -1;
} |