How to Start Windows Service automatically ?
To start windows service automatically after installation following below steps.
- We add OnAfterInstaller in the ProjectInstaller.cs File.
- AfterInstall event handler triggers immediately after Windows Service is installed
protected override void OnAfterInstall(IDictionary savedState)
{
base.OnAfterInstall(savedState);
//The following code starts the services after it is installed.
using (System.ServiceProcess.ServiceController serviceController =
new System.ServiceProcess.ServiceController(serviceInstaller1.ServiceName))
{
serviceController.Start();
}
}
>> Override the after installer class and the service controller make service run
automatically once the installation is complete.
Summary
Post a Comment