Windows Service Not Starting After Installing

24,115

Solution 1

to start your service you can either execute the command:

net start YourServiceName

or go to Control Panel -> Admin tools -> Services and select your service and click start.

full path above depends also on your actual windows version.

even if you did not use any logging, in general service failures are recorded in the Windows Event Log so open Event Viewer and see latest events.

Solution 2

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

Share:
24,115
Alon M
Author by

Alon M

Updated on May 26, 2020

Comments

  • Alon M
    Alon M almost 4 years

    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!

  • Alon M
    Alon M over 12 years
    The Service it self is automitaic, and i did an install and everything. but i need to go and strart the service my self, its dosent strat alone...
  • Alon M
    Alon M over 12 years
    There is no error. the service is fine, if i strart it my self it is working OK. The thing is i want after i install it it will strart by it self ><
  • Davide Piras
    Davide Piras over 12 years
    ok good, so as others told you specify Start Mode Automatic in the service installer
  • Davide Piras
    Davide Piras over 12 years
    This is what you are looking for: pietschsoft.com/post/2009/11/06/…
  • Pierre-Luc Champigny
    Pierre-Luc Champigny over 12 years
    Or this link, like I posted in my answer: devblog.grinn.net/2008/02/…
  • Alon M
    Alon M over 12 years
    Ok, i have create a windows service.then create a visualstudio installer. it is WORKING FINE!! i can strart the service by my self and its ok. BUT> if i dont strat it by my self after install. it iwll not STRAT. how can i do that after install it iwll strart by it self.
  • humblelistener
    humblelistener over 12 years
    You can start the service in multiple ways, one of them is to start it from service installer class using after install event. Refer here stackoverflow.com/questions/1036713/…
  • swdev
    swdev over 11 years
    This is what I am looking for! Thanks
  • Ahmad
    Ahmad over 3 years
    not working for me shows error "not installed service and rollback"