.net Windows 无法在 Win Server 2008 R2 SP1 上启动服务(错误 1053)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14121079/
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
Windows could not start service on Win Server 2008 R2 SP1 (Error 1053)
提问by jwaliszko
This issue seems to be widely discussed, but I have problems with finding the solution in my particular case.
这个问题似乎得到了广泛的讨论,但在我的特定情况下找到解决方案时遇到了问题。
My service is set up to be running under Local Systemaccount. On my first machine with Windows 7 SP1 (64-bit)installed, everything works as expected. But, just after I try to start the service on my second machine with Windows Server 2008 R2 SP1 (64-bit), not even a second passes, and I'm facing this annoying error:
我的服务设置为在Local System帐户下运行。在我安装了Windows 7 SP1(64 位)的第一台机器上,一切正常。但是,就在我尝试使用Windows Server 2008 R2 SP1 (64-bit)在我的第二台机器上启动该服务后,甚至没有一秒钟通过,我正面临这个烦人的错误:
Windows could not start the ProService service on Local Computer
Error 1053: The service did not respond to the start or control request in a timely fashion
The System Logshows 2 entries:
该System Log显示2项:
The ProService service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion.
and:
和:
A timeout was reached (30000 milliseconds) while waiting for the ProService service to connect.
The implementation looks following:
实现如下:
Program.cs:
程序.cs:
static void Main()
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
ServiceBase.Run(new ServiceBase[] { new ProService() });
}
static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e != null && e.ExceptionObject != null)
{
Logger.Record(e.ExceptionObject);
}
}
ProService.cs:
ProService.cs:
public ProService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
RequestAdditionalTime(10000);
FireStarter.Instance.Execute();
}
catch (Exception e)
{
Logger.Record(e);
throw;
}
}
The OnStartmethod is just starting a new thread, so it takes almost NO time load to execute. I used RequestAdditionalTimestatement just in case - to reject this matter as a source of my problem. In addition, as you can see, I'm handling all of the exceptions, but no exception is written to my custom service event log during the startup (btw: logging is working on the first win7 machine). How to investigate what's going on ?
该OnStart方法只是启动一个新线程,因此几乎不需要加载时间来执行。我使用RequestAdditionalTime声明以防万一 - 拒绝将此事作为我问题的根源。此外,如您所见,我正在处理所有异常,但在启动期间没有异常写入我的自定义服务事件日志(顺便说一句:日志记录正在第一台 win7 机器上运行)。如何调查发生了什么?
采纳答案by jwaliszko
I've figured out what was going on in a few steps:
我已经通过几个步骤弄清楚了发生了什么:
- I've written console application - wrapper for what is basically done in
OnStartmethod from service. - I've executed console application - application started normally.
- I've copied content of service configuration file to console application configuration file.
- I've executed console application once again - application aborted silently and immediately (surprisingly similar to our service behavior, something is wrong).
I've compared 2 configs - from service, and original from console application. As a result I've found some differences. Among others, there was such an entry - the source of the problem (after removal, everything works):
<startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup>
- 我已经编写了控制台应用程序 - 基本上在
OnStart服务方法中完成的内容的包装器。 - 我已经执行了控制台应用程序 - 应用程序正常启动。
- 我已将服务配置文件的内容复制到控制台应用程序配置文件。
- 我再次执行了控制台应用程序 - 应用程序以静默方式立即中止(与我们的服务行为惊人地相似,出了点问题)。
我比较了 2 个配置 - 来自服务和来自控制台应用程序的原始配置。结果我发现了一些差异。其中,有这样一个条目-问题的根源(删除后,一切正常):
<startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup>
So basically I had out of date configuration file. Previously service was compiled under .NET 4.5, then I've changed the framework to 4.0 and deployed files to the server, but left the previous configuration file (I've changed the target framework because my development machine has .NET 4.5 while server does not). I wouldn't have thought the shown lines would hide all problems without any reasonable information, which could help to track the mess.
所以基本上我有过时的配置文件。以前服务是在.NET 4.5下编译的,后来我把框架改成4.0,把文件部署到服务器,但保留了以前的配置文件(我改了目标框架,因为我的开发机器有.NET 4.5,而服务器没有不是)。我不会认为显示的线条会在没有任何合理信息的情况下隐藏所有问题,这有助于跟踪混乱情况。
回答by CoreTech
Check for missing dependencies/DLLs.
检查缺少的依赖项/DLL。
If you haven't already done so, allow your service to be invoked as a regular application (a great technique for long-term debugging) and see if it starts properly on your Windows 2008 machine.
如果您还没有这样做,请允许您的服务作为常规应用程序被调用(长期调试的一项很好的技术),并查看它是否在您的 Windows 2008 机器上正常启动。
If works that way, then there may be an issue with running in the LocalSystem account. Move on to starting your application from a command prompt running in the LocalSystem account (example setup here).
如果以这种方式工作,则在 LocalSystem 帐户中运行可能存在问题。继续从在 LocalSystem 帐户中运行的命令提示符启动您的应用程序(此处的示例设置)。
回答by Ramachandran Gokulachandran
I tried the following fix which was provided at this link
我尝试了此链接中提供的以下修复程序
Click Start, click Run, type regedit, and then click OK.
Locate and then click the following registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
- In the right pane, locate the ServicesPipeTimeout entry.
Note If the ServicesPipeTimeout entry does not exist, you must create it. To do this, follow these steps:
a. On the Edit menu, point to New, and then click DWORD Value.
b. Type ServicesPipeTimeout, and then press ENTER. - Right-click ServicesPipeTimeout, and then click Modify.
- Click Decimal, type 60000, and then click OK.
This value represents the time in milliseconds before a service times out. - Restart the computer.
单击开始,单击运行,键入 regedit,然后单击确定。
找到并单击以下注册表子项:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
- 在右窗格中,找到 ServicesPipeTimeout 条目。
注意如果 ServicesPipeTimeout 条目不存在,您必须创建它。为此,请按照下列步骤操作:
一。在编辑菜单上,指向新建,然后单击 DWORD 值。
湾 键入 ServicesPipeTimeout,然后按 Enter。 - 右键单击 ServicesPipeTimeout,然后单击修改。
- 单击小数,键入 60000,然后单击确定。
此值表示服务超时之前的时间(以毫秒为单位)。 - 重新启动计算机。
But still I had the problem to start the service.
但是我仍然遇到启动服务的问题。
The fix which worked for me was,
对我有用的修复是,
- Go the services.msc
- Double click the service which you are trying to start.
- Take the Logon Tab
- Changed Log on as: to Local System account.
- Tried starting the service after this change.(Still gave the 1053 error)
- Took the Log on tab again, changed it to Network Service (gave a random new password)
- Tried starting the service again.(The service started perfectly)
- 去服务.msc
- 双击您尝试启动的服务。
- 获取登录选项卡
- 将登录身份更改为:本地系统帐户。
- 尝试在此更改后启动服务。(仍然给出 1053 错误)
- 再次选择登录选项卡,将其更改为网络服务(随机提供一个新密码)
- 再次尝试启动服务。(服务完美启动)
回答by Srinivasan
I tried the below steps. It worked like a charm.
我尝试了以下步骤。它就像一个魅力。
1.Go the services.msc 2.Double click the service which you are trying to start. 3.Take the Logon Tab 4.Changed Log on as: to Local System account. 5.Tried starting the service after this change.(Still gave the 1053 error) 6.Took the Log on tab again, changed it to Network Service (gave a random new password) 7.Tried starting the service again.(The service started perfectly)
1.转到services.msc 2.双击您要启动的服务。3.Take 登录选项卡 4.Changed 登录为:到本地系统帐户。5.尝试在此更改后启动服务。(仍然出现1053错误) 6.再次选择登录选项卡,将其更改为网络服务(随机提供新密码) 7.再次尝试启动服务。(服务启动完美)
But I just want to know what will be the issue.
但我只想知道会出现什么问题。
回答by user5185809
After installing service, i have to gave full control permission(Everyone) for installation folder. Then, my service will started perfectaly.
安装服务后,我必须为安装文件夹授予完全控制权限(所有人)。然后,我的服务将完美启动。

