如何调试正在安装的Windows服务? [英] How do you debug a windows service that is being installed?

查看:159
本文介绍了如何调试正在安装的Windows服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何将调试器附加到Windows服务,但我似乎无法附加到正在安装并由Windows安装程序启动的程序。我试过:

I know how to attach a debugger to a windows service, but I can't seem to get attached to one that's being installed and started by a windows installer. I've tried:


  1. 设置Thread.Sleep(TimeSpan.FromSeconds(30));在开始的开始,但是当我尝试附加在Visual Studio中时,服务的名称不会显示为选项。通常情况下,服务的名称显示在列表中,但使用安装程序时不会。

  1. Setting a Thread.Sleep(TimeSpan.FromSeconds(30)); at the beginning of the on-start, but when I try to attach in Visual Studio, the name of the service does not appear as an option. This normally works, the service's name shows up in the list, but when using the installer it does not.

设置Debugger.Break和Debugger.Launch。

Setting a Debugger.Break and Debugger.Launch. Neither really do anything.

我可以如何调试我的服务?

What can I do to debug my service?

更新:

我添加了一个Thread.Sleep 30秒作为服务的第一行,当安装程序提示我失败时应该做什么,我在服务列表中启动服务(因为它还没有被删除),并且立即失败,没有30秒的等待。它安装的文件是最新的(他们有正确的修改时间)。如果我在同一个项目中从我的测试应用程序运行相同的客户端,但出于某种原因,安装程序会拧紧某些东西,则会发生30秒的暂停。

I added a Thread.Sleep for 30 seconds as the first line of the service, and when the installer is prompting me for what it should do when it fails, I start the service in the service list (since it hasn't been removed), and it fails instantly, without the 30 second wait. The files it installs are the latest (they've got the right modified time). The 30 second pause occurs if I run the same client from my test app in the same project, but for some reason the installer is screwing with something.

我真的不确定如何调试这个,令人沮丧的是这个服务用于正常工作。

I'm really not sure how to debug this, and the frustrating thing is that this service used to work properly.

答案:

检查应用程序日志显示了抛出的异常。原来我不小心在我的安装程序中砸了一个文件,这就解释了为什么我的调试技术都没有工作。一旦我恢复了这个文件,我就可以像Visual Studio一样安装(使用30秒的暂停给我时间)。

Checking the application log showed me the exception that was being thrown. It turned out I had accidentally clobbered a file in my installer, which explains why none of my debugging techniques worked. Once I restored the file, I was able to attach with visual studio as normal (using a 30 second pause to give me time).

推荐答案


  1. 在services.msc中,右键单击您的服务并选择属性。

  2. 启用登录选项卡允许服务与桌面交互。将 Debug.Assert(false,attach now); 添加到您的ServiceBase的OnStart方法中。

  3. 附加到该过程,并在断言对话框中单击忽略。

  1. In services.msc, right click on your service and choose properties.
  2. In the Log On tab enabled Allow the service to interact with the desktop.
  3. Add something like Debug.Assert(false, "attach now"); to your ServiceBase's OnStart method.
  4. Attach to the process and click ignore in the assert dialog.

编辑1:发生在我身上的事情,没有特定的顺序;

Edit 1: Things that occurr to me, in no particular order;

如果它曾经工作,是否可能不再像同一个用户一样运行?也许新用户没有相同的权限或更改权限。

If it used to work, is it possible that it's no longer running as the same user? Maybe the new user doesn't have the same permissions or the permissions changed.

使用事件查看器检查应用程序日志。

Use the Event Viewer to check the Application log.

如果安装过程中出现问题,则InstallUtil.InstallLog或{assemblyname} .InstallLog中可能会显示一些信息,这些信息与.exe相同。

If a problem is happening during the installation process there may be some info in InstallUtil.InstallLog or {assemblyname}.InstallLog, these would be in the same directory as the .exe.

我从我的Linux笔记本电脑上这样做,所以我有点模糊。

I'm doing this from my Linux laptop, so I'm a bit fuzzy.

编辑2:

在服务管理器中,右键单击您的服务并选择属性。验证服务指向正确的可执行文件;我已经看到后期制作步骤做的很棒的事情。

In the service manager, right click on your service and choose properties. Verify that the service to pointing to the correct executable; I've seen post build steps do funky things.

这篇关于如何调试正在安装的Windows服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆