1.有安装程序时:
正常情况下,我们开发windows服务时,会同时创建一个安装程序;
然后执行命令行安装。
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319 回车
InstallUtil.exe E:\TestApp\Winform\WinServiceTest\WinServiceTest\bin\Debug\WinServiceTest.exe 回车
或创建bat:
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe %~dp0\WindowsService1.exe
net Start WindowsService1
pause
卸载:
创建bat:
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe /u %~dp0\WindowsService1.exe
pause
2.没有安装程序时:
可以使用sc脚本安装;
安装:
@echo.-----服务启动......
@echo off
@sc create WinServiceTest binPath= E:\TestApp\Winform\WinServiceTest\WinServiceTest\bin\Debug\WinServiceTest.exe
@net start WinServiceTest
@sc config WinServiceTest start= AUTO
@echo off
@echo.-----启动完毕!
@pause
关闭:
@echo.-----服务关闭
@echo off
@net stop WinServiceTest
@echo off
@echo.-----关闭结束!
@pause
卸载:
@echo.-----服务删除
@echo off
@sc delete WinServiceTest
@echo off
@echo.-----删除结束!
@pause