如何自动启动服务安装后? [英] How to automatically start your service after install?
本文介绍了如何自动启动服务安装后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你如何自动运行从Visual Studio安装项目的安装后启动服务?
How do you automatically start a service after running an install from a Visual Studio Setup Project?
我只是想通这一个,以为我会分享在总体上是好的答案。答案可循。我愿意这样做,其他的更好的方法。
I just figured this one out and thought I would share the answer for the general good. Answer to follow. I am open to other and better ways of doing this.
推荐答案
添加下面的类到您的项目。
Add the following class to your project.
using System.ServiceProcess;
class ServInstaller : ServiceInstaller
{
protected override void OnCommitted(System.Collections.IDictionary savedState)
{
ServiceController sc = new ServiceController("YourServiceNameGoesHere");
sc.Start();
}
}
安装项目将拿起类,并安装完成后运行的服务。
The Setup Project will pick up the class and run your service after the installer finishes.
这篇关于如何自动启动服务安装后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文