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.
Use the .NET ServiceController class to start it, or issue the commandline command to start it --- "net start servicename". Either way works.
I've posted a step-by-step procedure for creating a Windows service in C# here. It sounds like you're at least to this point, and now you're wondering how to start the service once it is installed. Setting the StartType property to Automatic will cause the service to start automatically after rebooting your system, but it will not (as you've discovered) automatically start your service after installation.
I don't remember where I found it originally (perhaps Marc Gravell?), but I did find a solution online that allows you to install and start your service by actually running your service itself. Here's the step-by-step:
Structure the
Main()
function of your service like this:Here is the supporting code:
Continuing with the supporting code...
At this point, after you install your service on the target machine, just run your service from the command line (like any ordinary application) with the
-install
command line argument to install and start your service.I think I've covered everything, but if you find this doesn't work, please let me know so I can update the answer.