从可执行文件创建 Windows 服务 [英] Create Windows service from executable
问题描述
给定一个可执行文件,有没有什么快速的方法可以创建一个在启动时启动它的 Windows 服务?
Is there any quick way to, given an executable file, create a Windows service that, when started, launches it?
推荐答案
要从可执行文件创建 Windows 服务,您可以使用 sc.exe
:
To create a Windows Service from an executable, you can use sc.exe
:
sc.exe create <new_service_name> binPath= "<path_to_the_service_executable>"
exe
的实际路径必须用引号引起来,binPath=
后面必须有一个空格.
You must have quotation marks around the actual exe
path, and a space after the binPath=
.
可在 Microsoft KB251192 中找到有关 sc
命令的更多信息.
More information on the sc
command can be found in Microsoft KB251192.
请注意,它不适用于任何可执行文件:可执行文件必须是 Windows 服务 (即实现 ServiceMain).将非服务可执行文件注册为服务时,您将在尝试启动服务时收到以下错误:
Note that it will not work for just any executable: the executable must be a Windows Service (i.e. implement ServiceMain). When registering a non-service executable as a service, you'll get the following error upon trying to start the service:
错误 1053:服务没有及时响应启动或控制请求.
Error 1053: The service did not respond to the start or control request in a timely fashion.
有些工具可以从任意的非服务可执行文件创建 Windows 服务,请参阅其他答案以获取此类工具的示例.
There are tools that can create a Windows Service from arbitrary, non-service executables, see the other answers for examples of such tools.
这篇关于从可执行文件创建 Windows 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!