I've created a windows service in C (using WinAPI) and I want Visual Studio to automatically attach to the process of the service when I start the service from the Services panel. How can this be achieved. P.S. Putting a MessageBox at the service's initialization function and than manually attaching is no the kind of solution I'm looking for.
I found the solution.Simply add the following key in the registry:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\THE_NAME_OF_YOUR_SERVICE_EXECUTABLE.exe]
And add the following value and data:
"Debugger"="vsjitdebugger.exe"
Note that you'll have to remove this value when you're done testing, otherwise Visual Studio will prompt a message to attach whenever the service is started.
This works under Windows XP x32. I haven't tested on anything else.