1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
char processName[MAX_PATH];
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i=0;
//Enumeration des process
if (!EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return 0;
// Calcul du nombre des process.
cProcesses = cbNeeded / sizeof(DWORD);
while ((i < cProcesses))
{
if( aProcesses[i] != 0 )
{
// Ouverture process
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |PROCESS_VM_READ, FALSE, aProcesses[i] );
// Get the process name.
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if (EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded))
GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName)/sizeof(TCHAR) );
}
// Fermeture du HANDLE.
CloseHandle( hProcess );
WideCharToMultiByte(CP_ACP, NULL, szProcessName,MAX_PATH,processName,MAX_PATH, NULL, NULL);
if(!strcmp( processName,monProcess))
{
nbProc++;
/// HB 02/07/2018 : set pidAutonome : on est sure qu'il y a 2 autonome => pas besoin de parcourir le reste(nbProc ++ )
qDebug() << "nbProc "<< nbProc <<"# pid " <<aProcesses[i] << "# pid autonome courant "<<GetCurrentProcessId();
if(aProcesses[i] != GetCurrentProcessId())
{
pidAutonome = aProcesses[i];
}
/// END
}
}
i++;
}
return nbProc; |
Partager