Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Image Name and PrcessID

Image Name and PrcessID

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ranjan Banerji
    wrote on last edited by
    #1

    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.

    A 1 Reply Last reply
    0
    • R Ranjan Banerji

      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.

      A Offline
      A Offline
      adara
      wrote on last edited by
      #2

      #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; }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups