简体   繁体   English

无法调试Windows Service VS2010 Win7

[英]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. 从XP和VS2005迁移到Win7和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. 当我尝试附加到该进程时,就像在VS2005上一样,选择了正在运行的进程,并且收到一条错误消息,提示我需要管理员权限。

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. 另外,在互联网上搜索了很多之后,我发现以管理员身份(通过右键单击)运行VS2010应该可以解决该问题,但我仍然无法解决。

I also tried to mark the checkbox on vslauncher.exe properties to run it always as administrator. 我还尝试标记vslauncher.exe属性上的复选框以始终以管理员身份运行它。 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. VS2010窗口顶部显示它实际上是以管理员身份运行的,但是当我尝试附加到该进程时,它又说我需要管理员权限。

Has anybody any idea about how to proceed? 有人对如何进行有任何想法吗?

Edit your service and put the following line into the OnStart() method: 编辑您的服务,并将以下行放入OnStart()方法中:

Debugger.Launch(); 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. 请务必在OnStart()中执行此操作,而不是在OnStart()启动的线程中执行此操作,这样,如果有任何错误,可以在服务崩溃之前捕获它。

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. 然后,Windows将提供自动启动高架视觉工作室的功能,以便您可以附加到服务中。 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). 我发现将这一行与app.config设置放在一起非常有用,因此您可以根据需要启用它(即启动调试器并将其附加到服务)。

FYI when you use Vista / Windows 7 you can run apps as administrator. 仅供参考,当您使用Vista / Windows 7时,您可以以管理员身份运行应用程序。 However these apps explicitly reject administrative privileges unless you launch them with "Elevated" permissions. 但是,除非您使用“提升的”权限启动它们,否则这些应用程序会明确拒绝管理特权。 This is a security feature called UAC. 这是称为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: Win7带有一个新的安全系统,我必须将此权限添加到我的配置文件中(即使是管理员):

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. 谢谢大家的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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