You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

创建运行CMD文件的Windows服务时出现Error 1053错误求助

解决Windows服务启动报错Error 1053:服务未及时响应启动或控制请求

Hey, I’ve dealt with this exact Error 1053 problem when trying to run a CMD script as a Windows service before—let’s walk through what’s causing it and how to fix it.

问题场景与复现步骤

If you’re hitting this error, you’re probably following steps like this:

  • 以管理员身份打开CMD窗口
  • 执行命令:sc create test01 binPath="C:\test.cmd"
  • 创建C:\test.cmd并写入内容:echo test
  • 尝试在Windows服务列表中启动test01,随即弹出Error 1053: 服务未及时响应启动或控制请求

为什么会出现这个错误?

Windows services require executable programs that adhere to the Windows Service Control Manager (SCM) protocol—they need to handle start/stop control requests and keep running in the background. A plain CMD script doesn’t meet these requirements:

  1. When you point binPath directly to a .cmd file, Windows doesn’t automatically launch cmd.exe to execute it, so the service can’t initialize properly.
  2. Even if it did run, your echo test script exits immediately after executing, which the SCM interprets as a failed start (since services are meant to run continuously).

具体修复方案

Here are the most reliable fixes to get your CMD script running as a service:

1. 修正sc create命令的binPath参数

Instead of pointing directly to the .cmd file, you need to explicitly tell Windows to use cmd.exe to execute the script. Update your create command to:

sc create test01 binPath="cmd.exe /c C:\test.cmd"

(Note: If your script path has spaces, wrap the entire command in quotes and escape the inner path quotes, like binPath="cmd.exe /c \"C:\My Folder\test.cmd\""—the escaped quotes ensure the SCM parses the path correctly.)

2. 修改脚本让它持续运行

Since services need a persistent process to stay active, modify your test.cmd to keep running instead of exiting right away. For example:

@echo off
echo Service started at %date% %time% > C:\service_log.txt
:loop
rem 每隔60秒输出日志,保持进程活跃
echo Service running at %time% >> C:\service_log.txt
timeout /t 60 /nobreak > nul
goto loop

This way, the CMD process stays alive, and the SCM recognizes the service as running properly.

3. 调整服务启动超时时间(可选)

If your script needs extra time to initialize, you can increase the SCM’s timeout limit via the registry:

  • 打开注册表编辑器(regedit)
  • 导航到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
  • 找到ServicesPipeTimeout(如果不存在,右键新建一个DWORD (32-bit) Value并命名为这个)
  • 设置其值为十进制的60000(表示60秒,可根据需要调整)
  • 重启电脑使设置生效

4. 使用专门的服务托管工具(推荐)

For a more robust solution, use NSSM (Non-Sucking Service Manager)—it’s built to wrap scripts and regular programs into proper Windows services without manual protocol handling:

  • Download NSSM (no installation required)
  • Open an admin CMD window, navigate to the NSSM folder, and run:
    nssm install test01
    
  • A graphical window will pop up:
    • In the Path field, select C:\Windows\System32\cmd.exe
    • In the Arguments field, enter /c C:\test.cmd
    • Set optional settings like log paths if needed, then click Install service
  • You can now start/stop the service normally from the Services list, and it’ll handle SCM protocol interactions correctly.

内容的提问来源于stack exchange,提问作者Arsany

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:55:17