Image Name and PrcessID
-
How does TaskManager get the Image Name? If I iterate thru all windows using EnumWindows then I can get to the Handle for each window. Using the Handle I can get the processID using GetWindowThreadProcessId(hwnd, &wndPid); I can also get access to the ModuleName and GetWindowText. But none of these are the same as the Image Name we see on Task Manager. Is there a way to get the Image name from either the Handle to the Window or the ProcessID? Thanks.
-
How does TaskManager get the Image Name? If I iterate thru all windows using EnumWindows then I can get to the Handle for each window. Using the Handle I can get the processID using GetWindowThreadProcessId(hwnd, &wndPid); I can also get access to the ModuleName and GetWindowText. But none of these are the same as the Image Name we see on Task Manager. Is there a way to get the Image name from either the Handle to the Window or the ProcessID? Thanks.
#include #include #include #pragma comment (lib,"psapi.lib") int main(int argc, char* argv[]) { HANDLE hProc; char szProcessName [80]; HMODULE ahMod [10]; DWORD dwNeeded,dwPid; if(argc != 2) { printf("Usage: %s [pid]\n",argv[0]); return 0; } dwPid = atol(argv[1]); hProc = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,dwPid); if (hProc) { if (EnumProcessModules(hProc,ahMod,sizeof(ahMod),&dwNeeded)) { if(GetModuleBaseName(hProc,ahMod[0],szProcessName,sizeof(szProcessName))) printf("%s\n",szProcessName); else printf("%s\n","Not found"); } CloseHandle (hProc); } return 0; }