windows 错误 1053:服务没有及时响应启动或控制请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8130171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:56:00  来源:igfitidea点击:

Error 1053: The service did not respond to the start or control request in a timely fashion

windowsservice

提问by user1046592

I have an executable that I would like to set to run as a service. Using the sc.exe tool provided by windows (see KB article here: http://support.microsoft.com/kb/251192), I successfully "registered" the service. However, when I go to the Service Management Console (Start->Run->services.msc) and start the service, I get the following error:

我有一个可执行文件,我想将其设置为作为服务运行。使用 windows 提供的 sc.exe 工具(请参阅此处的知识库文章:http: //support.microsoft.com/kb/251192),我成功“注册”了该服务。但是,当我转到服务管理控制台(开始->运行->services.msc)并启动该服务时,出现以下错误:

Error 1053: The service did not respond to the start or control request in a timely fashion.

错误 1053:服务没有及时响应启动或控制请求。

After reading around my initial impression is that service executables have to conform to an API, and that among the required functions/methods a service has to respond to are a start/stop/restart command. However, this seems to defeat the whole point of the sc.exe tool which is advertised with the ability to turn any executable into a service.

在阅读之后,我的初步印象是服务可执行文件必须符合 API,并且在服务必须响应的必需函数/方法中,有一个启动/停止/重启命令。然而,这似乎破坏了 sc.exe 工具的全部意义,该工具被宣传为能够将任何可执行文件转换为服务。

Can anyone shed some light on this for me?

任何人都可以为我解释一下吗?

回答by brunobliss

This is the code you are looking for:

这是您正在寻找的代码:

sc create SERVICENAME binPath= "cmd /c c:\programlocation\program.exe" 

It will not rid you of error 1053, but at least this will apply to the console (CMD) who already did the job of running the app in the background (check task manager to confirm).

它不会让您摆脱错误 1053,但至少这将适用于已经在后台运行应用程序的控制台 (CMD)(检查任务管理器以确认)。

回答by Kurt Johnson

Take a look at Topshelf-projectwhich turns many arbitrary executables into services.

看看Topshelf-project,它将许多任意可执行文件转换为服务。

When you reference Topshelf, you can run your exe from a command-line, or install it into Windows Services with:

当您引用 Topshelf 时,您可以从命令行运行您的 exe,或使用以下命令将其安装到 Windows 服务中:

your.exe install

Even with topshelf registered, you would still want to have a logging facility -- such as log4net-- to monitor bootstrapping activities that could prevent it from launching in a timely fashion.

即使注册了 topshelf,您仍然希望有一个日志记录工具——比如log4net——来监视可能阻止它及时启动的引导活动。

回答by competent_tech

One very likely cause of this behavior is the application that is started is displaying a request for interaction with the end user (messagebox, input prompt, licensing dialog, etc). We have run into this more than once. This usually happens with applications that aren't designed to run as services. You could try running the service as Local System and check the Allow service to interact with desktopcheckbox.

这种行为的一个很可能的原因是启动的应用程序显示与最终用户交互的请求(消息框、输入提示、许可对话框等)。我们不止一次遇到过这种情况。这通常发生在并非设计为作为服务运行的应用程序中。您可以尝试将服务作为本地系统运行并选中Allow service to interact with desktop复选框。

The other possibility is that the user the service is configured to run as doesn't have access to resources (disks, databases, etc). If the process works correctly interactively, then try changing the service's user credentials to your user and see if that gets you any further.

另一种可能性是该服务被配置为运行的用户无权访问资源(磁盘、数据库等)。如果该过程以交互方式正常工作,则尝试将服务的用户凭据更改为您的用户,看看是否能让您更进一步。

Update

更新

Apologies, I assumed the question was regarding srvanywhich is the application you are looking for.

抱歉,我认为问题是关于srvany,这是您正在寻找的应用程序。