You can register yourself as a debugger for foo.exe through the image file options . At any time when the system needs to run foo.exe, it will launch your application and pass foo.exe and its parameters to you. You will need to start the process yourself.
Note: as usual, Raymond Chen, words of caution .
You can also set a system-wide message crawl, and for each new process that your dll will be loaded into, check to see if it matches you, just pass it, for foo.exe you notify yourself, and then go through. Unfortunately, this means that you will enter code into each process, and you will slightly damage the system. Not to mention that you can actually push everyone if you have a bug in your code.
source share