You need to get the full name of the executable file (exe) knowing the process ID.
Based on the statement that the executable itself is the first (main) module of the application, wrote this code:
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid); MODULEENTRY32 meModuleEntry; meModuleEntry.dwSize = sizeof(MODULEENTRY32); Module32First(hSnapshot, &meModuleEntry); if (INVALID_HANDLE_VALUE == hSnapshot) MessageBox(NULL, _T("ERROR"), _T("Information"), MB_ICONINFORMATION); else MessageBox(NULL, meModuleEntry.szExePath, _T("Information"), MB_ICONINFORMATION); Thus, if in pid transfer the identifier of the process, then everything works. But if you pass any other identifier (for example, explorer), then the hSnapshot variable takes the value INVALID_HANDLE_VALUE .
What am I doing wrong? Or is it not possible to view the modules of another process?
CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid)for 64-bit processes returnsINVALID_HANDLE_VALUE, and for 32-bit applications it works fine. - SHSERG