. Home Feedback Contents Search

Process Info 

Back Up Next

Program Name

Sometimes, the code needs to acquire the name of the program.

In Windows 98

  • Use GetForegroundWindow() to get the handle of the window that has the current focus.

  • Pass this handle to GetWindowModuleFileName(... ) to get the module's .exe name.

In Windows Nt/Win2K/XP

In Windows Win95/Win98, GetWindowModuleFileName(..) will work but fails in NT/Win2K/XP because module handles are not shared between all of the processes. Here’s an alternative that will work in NT/Win2K/XP:

  • Use GetForegroundWindow() to get the window of the window that has the current focus.

  • Call GetWindowThreadProcessId() to get the Process ID of that window window.

  • Enumerate all the processes using CreateToolhelp32Snapshot(..) ,Process32First() and Process32Next() }

  • Get the Modules list for the process with saved process id

  • Use GetModuleFileNameEx(..) or GetModuleBaseName(..) to get the module file name.

Back Up Next