开发者

How to auto start window service

开发者 https://www.devze.com 2023-01-31 14:39 出处:网络
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 t开发者_Python百科ime when system gets r

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 t开发者_Python百科ime when system gets restarted.

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


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


Try following way,

private void serviceInstaller_AfterInstall(object sender, InstallEventArgs e)
        {
            var service = new ServiceController(serviceInstaller.ServiceName);
            if (service.Status != ServiceControllerStatus.Running)
            {
                service.Start();
            }
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号