The easiest way I have found to do this is to put a call to System.Diagnostics.Debugger.Break()
in the Main()
function, the constructor, or the OnStart()
callback of your service. When you start the service from the SCM, you will be presented with a dialog that allows you to start a new instance of Visual Studio or attach to an existing instance. The service will stop at your programmatic breakpoint. You can debug from there.
Of course, all of this is predicated on the fact that you are actually able to debug a Windows service. The fact that you see the service in the "attach to" list, but it isn't highlighted indicates that you do not have sufficient privilege on your machine to debug it. Get with your system administrator to figure out what permissions are required. When I've done this, I've usually had to log off and log back on after the permissions were changed to get it to work.
EDIT:
I believe this echoes the infomation at the link @divo provided, but here is how I was able to get permission to debug my Windows service (straight from my system admin).
- Go to Start|Control Panel|Administrative Tools|Local Security Policy.
- Expand the local policies and click on User Rights Assignments.
- Look at the "Debug Programs" setting. Your username or primary group should be listed in this setting.
Note that if your system is a member of a domain, then this setting will be controlled by group policy and cannot be changed from the local machine level.