[英]How to install a Windows service developed in .NET 3.5?
I have developed a Windows service using Visual Studio 2008. I want to install that service in a machine where Visual Studio is not installed, but .NET 3.5 is installed. 我使用Visual Studio 2008开发了一个Windows服务。我想在没有安装Visual Studio但安装了.NET 3.5的机器上安装该服务。
Generally InstallUtil.exe shall be used for installing a Windows Service, but the InstallUtil.exe utility is not available in .NET 3.5. 通常,InstallUtil.exe将用于安装Windows服务,但.NET 3.5中不提供InstallUtil.exe实用程序。 When I tried installing that service using .NET 2.0, the service is getting displayed in the list of services but when starting the service Windows Service error 1053 is coming. 当我尝试使用.NET 2.0安装该服务时,该服务将显示在服务列表中,但在启动服务时,Windows服务错误1053即将到来。 How we can avoid this problem and successfully install the service? 我们如何避免这个问题并成功安装服务?
It's actually really simple as I just did it a couple of days ago for something I made. 它实际上非常简单,就像我几天前刚做的那样。
So in your service project you want to: 因此,在您的服务项目中,您希望:
Now you need to make a setup project. 现在你需要进行一个安装项目。 The best thing to do is use the setup wizard. 最好的办法是使用设置向导。
Now you need to edit your installer to make sure the correct output is included. 现在,您需要编辑安装程序以确保包含正确的输出。
Now just build your installer and it will produce an MSI and a setup.exe. 现在只需构建您的安装程序,它将生成一个MSI和一个setup.exe。 Choose whichever you want to use to deploy your service. 选择要用于部署服务的任何一种。
There's a Microsoft KB on this for .Net 2.0 and VS2005. 对于.Net 2.0和VS2005,有一个Microsoft KB。 The procedure is exactly the same in .Net 3.5 and VS2008. 该程序在.Net 3.5和VS2008中完全相同。
http://support.microsoft.com/kb/317421 http://support.microsoft.com/kb/317421
And here's a nicer article with pictures to make it clearer. 这是一篇更好的文章,图片更清晰。 (Sometimes the KB's aren't as friendly as tutorials you can find elsewhere.) (有时KB不像你在其他地方找到的教程那么友好。)
http://aspalliance.com/1316_Working_with_Windows_Service_Using_Visual_Studio_2005.3 http://aspalliance.com/1316_Working_with_Windows_Service_Using_Visual_Studio_2005.3
If you've been using InstallUtil.exe to install your Windows service, then that means you've added a ProjectInstaller component to your service. 如果您一直使用InstallUtil.exe来安装Windows服务,那么这意味着您已将ProjectInstaller组件添加到您的服务中。 All the InstallUtil.exe does is use reflection to find the installer component embedded in your service and execute some methods on it. 所有InstallUtil.exe都使用反射来查找服务中嵌入的安装程序组件并在其上执行一些方法。 Due to this, you can modify your Windows service to install and uninstall itself, ie, you no longer have to depend on InstallUtil.exe being available on the target machine . 因此,您可以修改Windows服务以自行安装和卸载,即您不再需要依赖目标计算机上可用的InstallUtil.exe 。 I've been using this successfully for several months now. 我已经成功使用了几个月了。 Just follow the step-by-step I provided here . 请按照我在此提供的步骤进行操作。 The idea originally belongs to Marc Gravell and this post . 这个想法最初属于Marc Gravell和这篇文章 。
The message: 消息:
"Error 1053: The service did not respond to the start or control request in a timely fashion." “错误1053:服务没有及时响应启动或控制请求。”
is typically a generic response to an issue starting the Windows Service. 通常是对启动Windows服务的问题的一般响应。 What you should do is check the event log and likely you will find the real error that is preventing the service from starting. 你应该做的是检查事件日志,你可能会发现阻止服务启动的真正错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.