要调试Windows服务,但弹出错误消息,提示 [英] want to debug a Windows service but it pops an error message saying

查看:137
本文介绍了要调试Windows服务,但弹出错误消息,提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调试Windows服务,但会弹出一条错误消息,内容为

无法从命令行或调试器启动服务.必须使用installutil.exe安装Windows服务,然后使用服务器资源管理器,Windows服务管理工具或NET启动命令启动Windows服务.

I want to debug a Windows service but it pops an error message saying

Cannot start service from the command line or a debugger. A windows service must be installed using installutil.exe and then started with the Server explorer, windows services Administrative tools or the NET start command.

推荐答案

要调试服务,请添加OnStart方法的延迟,例如Thread.Sleep(10000);.

然后,您必须将调试器附加到该进程 http://msdn.microsoft.com/en-us/library/c6wf8e4z.aspx [ ^ ].
To debug a service add a delay in the OnStart method like Thread.Sleep(10000);.

Then you have to attach your debugger to that process http://msdn.microsoft.com/en-us/library/c6wf8e4z.aspx[^].


看看这个页面:
http://msdn.microsoft.com/en-us/library/50614e95(VS .80).aspx [ ^ ]

installutil允许您安装和卸载服务-它们必须在服务控制管理器<下运行/a> [ ^ ].

我经常发现通过将实际实现与Windows服务实现分开来方便地使用Win窗体或命令行过程来测试服务的实现.

最好的问候
Espen Harlinn
Take a look at this page:
http://msdn.microsoft.com/en-us/library/50614e95(VS.80).aspx[^]

installutil lets you install, and uninstall services - they have to run under the service control manager[^].

I often find the convenient to test the implementation of a service using a win forms or command line process by separating the actual implementation from the windows service implementation.

Best regards
Espen Harlinn


我使用了另一种方法:开发可以在两种模式下运行的应用程序:作为Windows服务和交互式应用程序.该应用程序可以在运行时检测它当前是如何托管的,并且行为稍有不同.在交互模式下,它可以做更多的事情,例如,使用UI来立即显示日志记录.交互式模式使大多数调试方式更加容易.它还可以用于安装和卸载应用程序即服务,使用服务控制器启动/停止/重新启动在流程的另一个实例中运行的服务.

请查看我过去的解决方案:如何以编程方式安装Windows服务 [^ ].

—SA
I used alternative approach: developing of the application which can be run in both modes: as a windows service and as an interactive application. The application can detect during runtime how it is currently hosted and behave slightly differently. In interactive mode, it can do a lot more, for example, use UI to show logging immediately. The interactive mode makes most of the debugging way easier. It can also be used to install and uninstall the application as a service, start/stop/restart the service running in another instance of the process using Service Controller.

Please see my past solution: How to install windows service programmatically[^].

—SA


这篇关于要调试Windows服务,但弹出错误消息,提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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