Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Service Not Starting After Installing

Well, I have created a new windows service and the install from Visual Studio.

When I am done installing, how can I start the service ?

I need something that will allow me to start the process, or an exe.. something?

The Installer is : Visual Studio Installer - Setup Project.

Any help?

My question in order:

  1. Why the service don't start?

  2. How can i control what happen after intall ? Where is the code for it?

Thanks!

like image 797
Alon M Avatar asked Aug 31 '11 17:08

Alon M


1 Answers

even you Set the startup type to Automatic it will not start your service automatically until the machine restart. what you can do is create event handler for AfterInstall event of your service installer class and start the service using ServiceController Start method as below

public serviceInstaller()
{
    this.AfterInstall += new InstallEventHandler(serviceInstaller_AfterInstall);
}

void serviceInstaller_AfterInstall(object sender, InstallEventArgs e)
{
    ServiceController sc = new ServiceController(serviceInstaller.ServiceName);
    sc.Start();
}

you can create event using the visual studio event window as well.

how to create event from VS

like image 147
Damith Avatar answered Sep 20 '22 22:09

Damith