简体   繁体   中英

Can't debug windows Service VS2010 Win7

I am not able to debug any of my services after migrating from XP and VS2005, to Win7 and VS2010.

I can compile, I can install, I can run the services correctly.

But, I need to debug them. And when I try to attach to the process, I select the running process as I always did on VS2005, and I receive an error telling that I need admin permission.

I am already an administrator. Also, after searching a lot on the internet, I found that running VS2010 as an admin (via right click) should fix it, but I still can't.

I also tried to mark the checkbox on vslauncher.exe properties to run it always as administrator. The VS2010 window shows on top that it actually is running as admin, but again, when I try to attach to the process it says that I need admin rights.

Has anybody any idea about how to proceed?

Edit your service and put the following line into the OnStart() method:

Debugger.Launch(); It's important that you do this in OnStart() rather than a thread launched by OnStart() so that if there is any bug, you can catch it prior to your service crashing.

When your service starts the debugger will open. Windows will then offer to automatically launch an elevated visual studio so you can attach to your service. I find it very useful to put this line in with an app.config setting so you can enable it as required (ie launch and attach debugger to service).

FYI when you use Vista / Windows 7 you can run apps as administrator. However these apps explicitly reject administrative privileges unless you launch them with "Elevated" permissions. This is a security feature called UAC.

It was a permissions problem. Win7 comes with a new security system, and I had to add to my profile (even being an admin) this permission:

Control panel -> Administrative tools -> Local Security policy -> Local Policies -> User rights Assignment -> Debug programs -> Add user or group .

And there, I added my own user. Reboot machine(Important!! Without rebooting, it won't work).

After that, I was able to attach processes to debug them. It's been a really long time to solve this, I hope to help other people that find this same problem.

Thanks everybody for your help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM