How to auto start window service

2020-07-11 06:16发布

I have a window service which i developed in c# (vs2008). please tell me what should i do to make it auto start after installation and also auto start on every time when system gets restarted.

EDIT: I am using setup & deployment project to install it. Thanks

2条回答
啃猪蹄的小仙女
2楼-- · 2020-07-11 06:38

Follow the instructions given here to add an installer to your Service application. Pay particular attention to step 5, where you set the StartType property.

To start the service after installation, see Automatically start a Windows Service on install

查看更多
ゆ 、 Hurt°
3楼-- · 2020-07-11 06:55

Try following way,

private void serviceInstaller_AfterInstall(object sender, InstallEventArgs e)
        {
            var service = new ServiceController(serviceInstaller.ServiceName);
            if (service.Status != ServiceControllerStatus.Running)
            {
                service.Start();
            }
        }
查看更多
登录 后发表回答