用NSSM把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>"

但是:

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.

那就只能用第三方的了,有人推荐用NSSM:

http://nssm.cc/download

NSSM – the Non-Sucking Service Manager

名字简单又暴力,使用也是很简单暴力

下载,解压,找到32或者64位的exe

开一个管理权限的cmd,nssm.exe install SERVICENAME

回车,就有gui了,跟着gui走,完工