1、参考https://www.cnblogs.com/netcorner/archive/2012/05/02/2911916.html
https://blog.csdn.net/lwpkjio/article/details/85129507
https://blog.csdn.net/hany3000/article/details/83619283
2、使用InstallUtil.exe安装服务的批处理文件,以管理员身份运行
@echo off
set workpath=%~dp0
"%workpath%installutil.exe" /i "%workpath%..\test.exe"
Net Start test
sc config test start= auto
pause
@echo on
3、卸载
@echo off
set workpath=%~dp0
net stop test
"%workpath%installutil.exe" /u "%workpath%..\test.exe"
pause
@echo on
4、使用SC安装卸载的批处理文件
@echo off
set workpath=%~dp0
# binPath=后面需要有一个空格,否则在win7下安装不会成功,在命令行下只出现帮助
sc create testbinPath= "%workpath%..\test.exe" start= auto
Net Start test
pause
@echo on
@echo off
set workpath=%~dp0
Net stop test
sc delete test
pause
@echo on
5、C#创建服务的另一种方式:使用Topshelf创建服务程序。