Debug a Windows Service application in Visual studio 2005
For normal application we can set the breakpoint in Visual studio and start debugging by pressing F10 or F11. But for the Windows services application we can’t directly debug the application. Following steps will help to debug the windows service application.
1. Create the setup project for the Windows Service application.
2. If the Solution contain more than one Project, select the Windows Service project as the Start up project by right-click the project and select Set as Startup project
3. In the Solution configuration select Debug mode. In the release mode we can’t debug the application.
4. Install the Windows service setup in the system
5. Go to the services and start your windows services. Once it successfully started proceed to next step.
6. Set Breakpoint on your application( press F9 for breakpoint)
7. Go to Tools–>Options menu in the VS 2005
8. Select Debugging –>Symbols
9. In the Symbol file(.pdb) locations add the path of the pdb file path.(should include the pdb file name also)
i.e \Debug\
10. The Pdb file is located in the application Debug directory.
11. In the Cache symbols servers to this directory browse the path where the Pdb file is located.(no pdb file name required here. Only path up to Debug folder)
12. Click ok to set your setting. After finishing this again to this window and double check that your options are still available.
13. Select Debug–>Attach to Process option as shown in fig
14. Select your running windows service in the Available processes
15. Click Attach button to attach the Windows service to your application.
16. Now you can see the application is starts running.
17. Please wait until the flow reaches your breakpoint.
18. Once it reaches your breakpoint then you can use your normal F10 or F11 keys to debug the application.
happy Coding!!!



Could you please advice why is the service grayed out (in the attached to process screen) after i call InstallUtil.exe serviceCode.exe
thanks,
Eila
By: Eila on March 14, 2009
at 2:21 pm
I could not understand what you are looking for..? Can you explain it more?
By: R Manimaran on March 31, 2009
at 6:12 am
Great article !! The method of attaching has to be quick though .. isn’t it? …. I found this interesting too …
http://mycomponent.blogspot.com/2009/04/create-debug-install-windows-service-in.html
By: Javs on April 8, 2009
at 12:46 am
Great article !! The method of attaching has to be quick though .. isn’t it? …. I found this interesting too …
http://mycomponent.blogspot.com/2009/04/create-debug-install-windows-service-in.html
By: Javs on April 8, 2009
at 12:47 am