Registry
Typically you would add an entry into the Image File Execution Options
registry area, which lets you invoke a debugger as soon as the named exe is launched.
Assuming a 64bit service:
- Key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\App1.exe
- Value:
debugger
REG_SZ
- Data:
"C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\windbg.exe"
Notice the name of your exe in the Key path, and any specific debugger (and command line parameters) can be specified.
For 32-bit services, add your new entry to the HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\[app.exe]
path.
Just remember to delete (or temporarily rename) the registry when done debugging.
DebugBreak
Alternately, you can add a call to DebugBreak at the start of your process. Its worthwhile to add the check for an app-specific registry setting before calling DebugBreak, that way it is easy to turn on and off.