📜  将 exe 注册为 Windows 服务 - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:25.678000             🧑  作者: Mango

代码示例1
To create a Windows Service from an executable, you can use sc.exe: (Run as Admin !!)

sc.exe create  binPath= ""
You must have quotation marks around the actual exe path, and a space after the binPath=.

More information on the sc command can be found in Microsoft KB251192.

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:

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

There are tools that can create a Windows Service from arbitrary, non-service executables, see the other answers for examples of such tools.