Friday, September 26, 2008

Can you debug a Windows Service? How?

Can you debug a Windows Service? How?

Yes we can debug a Windows Service.
Attach the WinDbg debugger to a service after the service starts
This method is similar to the method that you can use to attach a debugger to a process and then debug a process.

Use the process ID of the process that hosts the service that you want to debug

1. To determine the process ID (PID) of the process that hosts the service that you want to debug, use one of the following methods.

• Method 1: Use the Task Manager
a. Right-click the taskbar, and then click Task Manager. The Windows Task Manager dialog box appears.
b. Click the Processes tab of the Windows Task Manager dialog box.
c. Under Image Name, click the image name of the process that hosts the service that you want to debug. Note the process ID of this process as specified by the value of the corresponding PID field.

• Method 2: Use the Task List Utility (tlist.exe)
a. Click Start, and then click Run. The Run dialog box appears.
b. In the Open box, type cmd, and then click OK.
c. At the command prompt, change the directory path to reflect the location of the tlist.exe file on your computer.

Note the tlist.exe file is typically located in the following directory: C:\Program Files\Debugging Tools for Windows
d. At the command prompt, type tlist to list the image names and the process IDs of all processes that are currently running on your computer.

Note make a note of the process ID of the process that hosts the service that you want to debug.