7

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!

Yury Schkatula
  • 5,291
  • 2
  • 18
  • 42
Alon M
  • 1,583
  • 7
  • 30
  • 44
  • 1
    This question needs to be clarified greatly. What is the error when you attempt to start the service? – Tejs Aug 31 '11 at 17:34

7 Answers7

10

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

Damith
  • 62,401
  • 13
  • 102
  • 153
5

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.

Davide Piras
  • 43,984
  • 10
  • 98
  • 147
  • 1
    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 > – Alon M Aug 31 '11 at 17:41
  • ok good, so as others told you specify Start Mode Automatic in the service installer – Davide Piras Aug 31 '11 at 17:45
  • This is what you are looking for: http://pietschsoft.com/post/2009/11/06/dotNet-Windows-Service-Installer-And-Auto-Start-After-Installation.aspx – Davide Piras Aug 31 '11 at 17:45
  • Or this link, like I posted in my answer: http://devblog.grinn.net/2008/02/windows-services-in-c-part-3-getting.html – Pierre-Luc Champigny Aug 31 '11 at 17:48
0

Your Windows service working in some systems. If you face some system getting error Windows Service not starting after installing if manually/automatically.

if the service starts and stops like that, it means your code is throwing an unhandled exception. This is pretty difficult to debug, but there are a few options.

  1. Consult the Windows Event Viewer.

Event Viewer - eventvwr.msc

Normally you can get to this by going to the computer/server manager, then clicking Event Viewer -> Windows Logs -> Application. You can see what threw the exception here, which may help, but you don't get the stack trace. Event Viewer Log Image

  1. Add try/catch block in your service start method.

  2. Let you check whether you are using any hot code(For Ex: "D:\"). That drive is not available in installed system.

This will helps a lot!

HemaPrabhu
  • 1
  • 1
  • 2
0

Set the startup type to Automatic in the ServiceInstaller class properties (you can do it in the Designer file).

Jeff
  • 35,755
  • 15
  • 108
  • 220
  • 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 Aug 31 '11 at 17:37
0

A windows service needs to be installed ( it should tell you what to do if you try debugging it ), then started in the server manager. Then you can attach to it.

They are a bit of a pain to debug, TBH.

Schroedingers Cat
  • 3,099
  • 1
  • 15
  • 33
0

What does the service do? is it opening SQL connections? looking for a file? check in your event viewer where the service is installed for errors after you try to start it, it will give us a better understanding.

  • There is no error, the service is fine, the problem is that i need to strart it my self after install. and i want it to strat by it self..<> – Alon M Aug 31 '11 at 17:39
  • 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. – Alon M Aug 31 '11 at 17:50
0

It is impossible to understand your question unless you take interest in making it understandable.

However from my assumption,

Goto Visual studio Tools => Visual Studio command prompt use command net start <>

If fails starting the servicce, Check event log (eventvwr.msc in run dialog) to see if there any relevant errors logged.

humblelistener
  • 1,456
  • 12
  • 22
  • 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. – Alon M Aug 31 '11 at 17:50
  • 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 http://stackoverflow.com/questions/1036713/automatically-start-a-windows-service-on-install – humblelistener Aug 31 '11 at 18:12