简体   繁体   English

安装后Windows服务无法启动

[英]Windows Service Not Starting After Installing

Well, I have created a new windows service and the install from Visual Studio. 好吧,我已经创建了一个新的Windows服务和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? 我需要的东西可以让我开始这个过程,或者一个exe ......某些东西?

The Installer is : Visual Studio Installer - Setup Project. 安装程序是:Visual Studio Installer - 安装项目。

Any help? 有帮助吗?

My question in order: 我的问题依次为:

  1. Why the service don't start? 为什么服务无法启动?

  2. How can i control what happen after intall ? 我怎样才能控制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 你可以做的是为服务安装程序类的AfterInstall事件创建事件处理程序,并使用ServiceController Start方法启动服务,如下所示

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. 您也可以使用visual studio事件窗口创建事件。

如何从VS创建事件

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. 上面的完整路径还取决于您的实际Windows版本。

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. 即使您没有使用任何日志记录,通常服务失败也会记录在Windows事件日志中,因此打开事件查看器并查看最新事件。

Your Windows service working in some systems. 您的Windows服务在某些系统中工作。 If you face some system getting error Windows Service not starting after installing if manually/automatically. 如果您遇到某些系统获取错误,则在安装后如果手动/自动启动Windows服务无法启动。

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. 请参阅Windows事件查看器。

Event Viewer - eventvwr.msc 事件查看器 - eventvwr.msc

Normally you can get to this by going to the computer/server manager, then clicking Event Viewer -> Windows Logs -> Application. 通常,您可以通过转到计算机/服务器管理器,然后单击“事件查看器” - >“Windows日志” - >“应用程序”来实现此目的。 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. 在服务启动方法中添加try / catch块。

  2. Let you check whether you are using any hot code(For Ex: "D:\\"). 让您检查是否使用任何热代码(例如:“D:\\”)。 That drive is not available in installed system. 该驱动器在已安装的系统中不可用。

This will helps a lot! 这将有很大帮助!

在ServiceInstaller类属性中将启动类型设置为自动(您可以在Designer文件中执行此操作)。

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. 需要安装Windows服务(它应该告诉您如果尝试调试它该怎么做),然后在服务器管理器中启动。 Then you can attach to it. 然后你可以附加它。

They are a bit of a pain to debug, TBH. 调试它们有点痛苦,TBH。

What does the service do? 这项服务有什么作用? is it opening SQL connections? 是打开SQL连接? 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 <> 转到Visual Studio Tools => Visual Studio命令提示符使用命令net start <>

If fails starting the servicce, Check event log (eventvwr.msc in run dialog) to see if there any relevant errors logged. 如果无法启动服务,请检查事件日志(运行对话框中的eventvwr.msc)以查看是否记录了任何相关错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM