本文介绍了如何让正确安装后一个.NET Windows服务启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
除了service.StartType = ServiceStartMode.Automatic我的服务安装后不会启动
Besides the service.StartType = ServiceStartMode.Automatic my service does not start after installation
解决方案
插入此code对我ProjectInstaller
Inserted this code on my ProjectInstaller
protected override void OnAfterInstall(System.Collections.IDictionary savedState)
{
base.OnAfterInstall(savedState);
using (var serviceController = new ServiceController(this.serviceInstaller1.ServiceName, Environment.MachineName))
serviceController.Start();
}
由于ScottTx和弗朗西斯湾
Thanks to ScottTx and Francis B.
推荐答案
您可以在响应来自InstallUtil过程中触发的事件做这一切从服务的可执行文件中。重写OnAfterInstall事件使用的ServiceController类来启动服务。
You can do this all from within your service executable in response to events fired from the InstallUtil process. Override the OnAfterInstall event to use a ServiceController class to start the service.
http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstaller.aspx
这篇关于如何让正确安装后一个.NET Windows服务启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!