Réponse acceptée !
#include <windows.h>
#include <tlhelp32.h> //th32.lib ou libth32.a
#include <stdio.h>
//---------------------------------------------------
DWORD GetPidByName(char *szProcName)
{
DWORD dwPID = 0;
PROCESSENTRY32 pe = {sizeof(PROCESSENTRY32)};
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hSnap != INVALID_HANDLE_VALUE)
{
if(Process32First(hSnap, &pe))
{
do
{
if(strcmpi(pe.szExeFile, szProcName) == 0)
{
dwPID = pe.th32ProcessID;
break;
}
}
while(Process32Next(hSnap, &pe));
}
CloseHandle(hSnap);
}
return dwPID;
}
//---------------------------------------------------
int main(void)
{
printf("PID = %ld\n", GetPidByName("explorer.exe"));
return 0;
}