windows启动时自动启动服务 [英] Start service automatically when windows start
本文介绍了windows启动时自动启动服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 windows server 2008 r2 中安装了一个服务,想在 windows 启动时启动它
I install a service in windows server 2008 r2 , and want to start it when windows start
class Program : ServiceBase
{
...
static void Main(string[] args)
{
ServiceBase.Run(new Program());
}
public Program()
{
this.ServiceName = "ABPS";
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
this.start();//a method that start works
}
...
推荐答案
你应该向您的应用程序添加安装程序.
要确定您的服务将如何启动,请点击ServiceInstaller 组件并将 StartType 属性设置为适当的值.
To determine how your service will be started, click the ServiceInstaller component and set the StartType property to the appropriate value.
- Manual 服务必须手动安装后启动.
- Automatic 服务将在任何时候自动启动计算机重新启动.
- Disabled 服务无法启动.
您可以在 AfterInstall
事件处理程序中启动您的服务
you can start your service in AfterInstall
event handler
void ServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
{
using (ServiceController sc = new ServiceController(serviceInstaller.ServiceName))
{
sc.Start();
}
}
这篇关于windows启动时自动启动服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文