简体   繁体   English

Windows无法启动服务

[英]Windows can't start service

I am developing an app to install & run as a Windows service. 我正在开发一个应用程序来安装和运行Windows服务。 It's still buggy and stopped unexpectedly (leaving nothing in the Windows Event log either) and when I tried to start it up again I got the error 它仍然是错误的并且意外停止(在Windows事件日志中也没有留下任何内容)当我尝试再次启动时我得到了错误

Windows could not start the {name of service} service on Local Computer. Windows无法在本地计算机上启动{name of service}服务。 Error 1067: The process terminated unexpectedly. 错误1067:进程意外终止。

I restarted the computer (Server 2008 R2; a virtual machine, in case that makes a difference), no help. 我重新启动了计算机(Server 2008 R2;虚拟机,如果有所作为),没有帮助。 Uninstalled and reinstalled my service, and still get that error! 卸载并重新安装我的服务,仍然出现错误!

Something on the machine needs cleared out / refreshed so that it will attempt to start the service again. 机器上的某些东西需要清除/刷新,以便它再次尝试启动服务。 I don't want to rebuild the whole virtual machine but I'm out of ideas. 我不想重建整个虚拟机,但我没有想法。

UPDATE UPDATE

I forgot to mention that this Windows service -- exact same code & install -- is running on 3 other machines without the above error. 我忘了提到这个Windows服务 - 完全相同的代码和安装 - 在没有上述错误的其他3台机器上运行 Putting in that debugger in OnStart() still sounds like the way to go though. 在OnStart()中放入调试器仍然听起来像是要走的路。

If you have access to the code, you can add a method Debugger.Break at the first line of the OnStart method. 如果您有权访问代码,则可以在OnStart方法的第一行添加方法Debugger.Break

Once you "break" into the application investigate where the exception is thrown. 一旦你“闯入”应用程序,调查抛出异常的位置。

You can attach the debugger to a running service. 您可以将调试器附加到正在运行的服务。 Details at Debug Windows Service Applications . 调试Windows服务应用程序的详细信息

It's fortunate that you can replicate the problem easily. 幸运的是,您可以轻松地复制问题。 You can install the .NET Studio with code to debug your problem. 您可以使用代码安装.NET Studio来调试问题。

Another technique is to make the Service into a regular app. 另一种技术是将服务变成常规应用程序。 You know that the suspect code is during Startup. 您知道可疑代码是在启动期间。 So simply create the app with code in the Startup function, and start debugging from there. 因此,只需在启动功能中使用代码创建应用程序,然后从那里开始调试。

Good luck, 祝好运,

Tommy Kwee 汤米克威

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

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