views:

102

answers:

3

I am trying to attach to a windows service using the Visual Studio 2010 --> Debug --> attach to process command. When i scroll through the list of processes my windows service is greyed out and the attcah button is also greyed out. I have tried changing the service account to loacal service, my account, etc but it remains greyed out. Anyone have any suggestions or anyway to troubleshoot this?

+1  A: 

Make sure you run Visual Studio as an Administrator. It will require administrator rights to attach to a running Service.

Reed Copsey
Tried this but no luck. I can attach to other services listed in the process list, just not the one i need to. :)
Kevin McPhail
+1  A: 

You may not have permissions to attach to the service. Do you have admin privileges on the desktop? Many corporations do not allow this by default, supposedly to assist in securing their environment.

Steve Townsend
Yea, i have admin privs and i tried to right click and run as administrator in vs to see if that helped. No luck.
Kevin McPhail
Are you in a position to try the Alternate Debugging Strategies described here: http://msdn.microsoft.com/en-us/library/7a50syb3(VS.80).aspx ?
Steve Townsend
Steve, thanks for the link. I had actually looked at that page but did not see the alternate strategies at the bottom. I have used a console to test services before and that is a pretty decentalternative.
Kevin McPhail
Welcome. I'd be interested to know how this was or is resolved for you.
Steve Townsend
+1  A: 

I usually have the same issue and I take care of it by adding a bool to my config that triggers a debug launch. You can launch a VS debugger instance that attaches to your win service process by calling this:

System.Diagnostics.Debugger.Launch();

What's nice is you can call it wherever you wish in your code.

jlafay
I like this. A nice simple way to launch a debugger from a service. Next question is there a way to remotely attach using this method if the service is installed on another machine?
Kevin McPhail
Don't have an immediate answer but that would be beneficial to me as well. I'll see if there's an easy way to achieve it and if so I'll edit my answer to include that solution as well.
jlafay