Attach a Debugger When a Process Starts
You can ask Windows to launch another process (typically a debugger) when launching a process of your choice.
One use of this feature is to configure Calculator to launch whenever you launch Notepad, or configure Excel to launch whenever you launch Word. This is a great way to drive a colleague crazy.
Another use of this feature is to attach a debugger to the startup sequence of a process that can’t be easily started from within the debugger. For example, if you’re debugging the startup of a Windows service, you can’t start it from the debugger; the same applies to dllhost.exe processes in a COM+ environment; and there are other examples.
All you need to do to configure this feature is the Global Flags application available with the Debugging Tools for Windows package. In the Image File tab, input the executable name (including the extension) and hit Tab to refresh, and then check the Debugger checkbox and input the name of the debugger to launch. Finally, click Apply—no system restart is required.
There’s no dark debugger magic involved—when Windows launches the ‘target’ process, it checks the registry for the appropriate flag and if it’s present, it will launch the specified process, pass to it the ‘target’ executable name as the first command line parameter, followed by the rest of the original command line arguments.
For example, to configure Calculator to launch whenever you launch Notepad:
A more useful example, where you configure the Visual Studio debugger to launch when you launch MyApp.exe:
