I have developed a windows service, but need it to start automatically on install. Problem is that every tutorial I found is showing me through the Setup Project
. There is a fantastic 3 part tutorial HERE that I used to convert my app to a service, but I don't have the Setup Project
in my other project types. Can I do this programatically or is there a way I can get the Setup Project
project type?
In your Installer class, add a handler for the AfterInstall event. You can then call the ServiceController in the event handler to start the service.
public ServiceInstaller()
{
//... Installer code here
this.AfterInstall += new InstallEventHandler(ServiceInstaller_AfterInstall);
}
void ServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
{
using (ServiceController sc = new ServiceController(serviceInstaller.ServiceName))
{
sc.Start();
}
}
Now when you run InstallUtil on your installer it will install and then start up the service.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments