How to auto start window service

孤人 提交于 2019-12-12 08:53:14

问题


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


回答1:


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




回答2:


Try following way,

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


来源:https://stackoverflow.com/questions/4468148/how-to-auto-start-window-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!