In this article I will explain how to automatically start a Windows Service after installation is completed using C# and VB.Net.
The Windows Service will be started automatically after the installation is completed by making use of the AfterInstall event handler.
Making the Windows Service Automatically start after Installation
After the installation one has to start the Windows Service manually through the Services section of My Computer Management.
We can start the Windows Service automatically after installation by making use of the AfterInstall event handler which triggers immediately after Windows Service is installed.
You will need to open the ProjectInstaller class and override the AfterInstall event handler and add the code to start the Windows Service.
public partial class ProjectInstaller : System.Configuration.Install.Installer
    public ProjectInstaller()
    protected override void OnAfterInstall(IDictionary savedState)
        //The following code starts the services after it is installed.
        using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController(serviceInstaller1.ServiceName))
Public Class ProjectInstaller
    Public Sub New()
        'This call is required by the Component Designer.
        'Add initialization code after the call to InitializeComponent
    End Sub
    Protected Overrides Sub OnAfterInstall(savedState As IDictionary)
        'The following code starts the services after it is installed.
        Using serviceController As New System.ServiceProcess.ServiceController(ServiceInstaller1.ServiceName)
        End Using
    End Sub
End Class