Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Win32: Get message notification of other application's close/exit

My application needs to monitor all other running applications on the system. Is there some way I could get notified on exit of every application exe?

The methods I could find:

1) Use PSAPI functions to get the list of running exes at frequent intervals. At each poll compare with the previous list to find which application/process has exited. Disadvantage: Requires constant polling, will take CPU time.

2) Set a global hook for WM_CLOSE message: Using this I would be able to get a notification when any application gets closed through the close button on the title bar

Disadvantage: (-)Not all the applications are generating a WM_CLOSE message(Ex: Total Video Player Exe) (-)If the application was closed through the "Exit" menu or button (e.g. File->Exit) , I can't trap that message

Is there any other better way that I missed? Please advise.

like image 259
WindowsPistha Avatar asked Dec 18 '22 08:12

WindowsPistha


1 Answers

  1. Get a list of PIDs using PSAPI.
  2. Then get a handle on each process using OpenProcess().
  3. Use WaitForMultipleObjects() to be signalled when one of the processes exits.
like image 70
Serge Wautier Avatar answered Apr 28 '23 04:04

Serge Wautier