Code:
int GetTheRealAowProcId()
{
DWORD dwRet = 0;
DWORD dwThreadCountMax = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
Process32First(hSnapshot, &pe32);
do
{
if (_tcsicmp(pe32.szExeFile, _T("aow_exe.exe")) == 0)
{
DWORD dwTmpThreadCount = GetProcessThreadNumByID(pe32.th32ProcessID);
if (dwTmpThreadCount > dwThreadCountMax)
{
dwThreadCountMax = dwTmpThreadCount;
dwRet = pe32.th32ProcessID;
}
}
} while (Process32Next(hSnapshot, &pe32));
CloseHandle(hSnapshot);
return dwRet;
}