A new way to debug a windows service

Normally when you want to debug a service at startup you set your debug break point and set the thread asleep just long enoug for you to attach your debugger to the service process but, came across a more eloquent way

Setup:

Ø Follow the instructions in ‘Configure a service to start with the WinDbg debugger attached’ section of the KB article – KB 824344. Note that you can safely ignore Step 2 in this section as you would no longer need the service to interact with desktop.

Ø Add the following command line parameters to the path of the debugger: (let’s assume debugger is installed in ‘C:\Debuggers’ instead of ‘C:\Program Files\Debugging Tools for Windows’ for convenience)

C:\Debuggers\WinDBG.exe -G -c ".server tcp:port=1234"

Ø Start your service from Service Control Manager.

Ø By now the debugger is already connected to the service as a ‘server’. You would have reached the ‘Initial Breakpoint’ waiting for a g (Go) command from the debugger.

Ø Launch another instance of WinDBG and connect to the ‘server’. There are many ways to do this; the simplest would be to go to File->Connect to Remote Session->Browse->Enter machine name->Refresh. Hit OK on your ‘server’ that is listed to connect.

Read the rest of the post A look at service startup issues.

Comments [0]