开发者

Windows Service Not Starting After Installing

开发者 https://www.devze.com 2023-03-31 21:18 出处:网络
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 ?

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 questio开发者_C百科n 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!


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.

Windows Service Not Starting After Installing


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.


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


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.


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.


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.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消