Bonjour
je voudrais recuperer le handle d'un processus active ex :explorer.exe
jai deja un code similaire mais il trouve que le PID a partir du processus
#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", GetByName("explorer.exe"));
system("pause>nul");
return 0;
}
Pouriez-vous maider
Kevin