Besides the service.StartType = ServiceStartMode.Automatic my service does not start after installation
Solution
Inserted this code on my ProjectInstaller
protected override void OnAfterInstall(System.Collections.IDictionary savedState)
{
base.OnAfterInstall(savedState);
using (var serviceController = new ServiceController(this.serviceInstaller1.ServiceName, Environment.MachineName))
serviceController.Start();
}
Thanks to ScottTx and Francis B.
You can do this all from within your service executable in response to events fired from the InstallUtil process. Override the OnAfterInstall event to use a ServiceController class to start the service.
http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstaller.aspx
To start it right after installation, I generate a batch file with installutil followed by sc start
It's not ideal, but it works....
You need to add a Custom Action to the end of the 'ExecuteImmediate' sequence in the MSI, using the component name of the EXE or a batch (sc start) as the source. I don't think this can be done with Visual Studio, you may have to use a real MSI authoring tool for that.
To add to ScottTx's answer, here's the actual code to start the service if you're doing it the Microsoft way (ie. using a Setup project etc...)
(excuse the VB.net code, but this is what I'm stuck with)
To create the above event handler, go to the ProjectInstaller designer where the 2 controlls are. Click on the ServiceInstaller1 control. Go to the properties window under events and there you'll find the AfterInstall event.
Note: Don't put the above code under the AfterInstall event for ServiceProcessInstaller1. It won't work, coming from experience. :)
Visual Studio
If you are creating a setup project with VS, you can create a custom action who called a .NET method to start the service. But, it is not really recommended to use managed custom action in a MSI. See this page.
InstallShield or Wise
If you are using InstallShield or Wise, these applications provide the option to start the service. Per example with Wise, you have to add a service control action. In this action, you specify if you want to start or stop the service.
Wix
Using Wix you need to add the following xml code under the component of your service. For more information about that, you can check this page.
The easiest solution is found here install-windows-service-without-installutil-exe by @Hoàng Long