How do you automatically start a service after running an install from a Visual Studio Setup Project?
I just figured this one out and thought I would share the answe
Based on the snippets above, my ProjectInstaller.cs file wound up looking like this for a service named FSWServiceMgr.exe. The service did start after installation. As a side note, remember to click on the Properties tab (not right-click) when the setup project is selected in the Solution Explorer to set the company and so forth.
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;
namespace FSWManager {
[RunInstaller(true)]
public partial class ProjectInstaller : Installer {
public ProjectInstaller() {
InitializeComponent();
this.FSWServiceMgr.AfterInstall += FSWServiceMgr_AfterInstall;
}
static void FSWServiceMgr_AfterInstall(object sender, InstallEventArgs e) {
new ServiceController("FSWServiceMgr").Start();
}
}
}