一、新建项目 选中windows服务windows
二、添加安装程序测试
三、修改安装代码this
ServiceProcessInstaller processInstall; ServiceInstaller serviceInstall; public ProjectInstaller() { this.processInstall = new ServiceProcessInstaller(); this.serviceInstall = new ServiceInstaller(); processInstall.Account = ServiceAccount.LocalSystem; this.serviceInstall.ServiceName = "ABC_TaskService"; this.serviceInstall.Description = "ABC_Description"; this.Installers.Add(this.serviceInstall); this.Installers.Add(this.processInstall); }
四、从新生成项目spa
五、新建bat文件(安装服务.bat)blog
@ECHO OFF REM The following directory is for .NET1.1 set DOTNETFX=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319 set PATH=%PATH%;%DOTNETFX% cd\ cd "G:\WindowsServiceTest\WindowsServiceTest\bin\Debug" echo 正在安装 测试服务 echo --------------------------------------------------- InstallUtil /i WindowsServiceTest.exe sc config "ABC_TaskService" start= auto Net Start "ABC_TaskService" echo --------------------------------------------------- pause
注意:ip
一、cd "G:\WindowsServiceTest\WindowsServiceTest\bin\Debug" 路径为项目的路径get
二、InstallUtil /i WindowsServiceTest.exe 其中WindowsServiceTest为项目从新生成的文件名称it
三、sc config "ABC_TaskService" start= auto 其中ABC_TaskService为第三步为服务起的名称io
四、执行bat文件时必定要在管理员:命令提示符中操做 不然会错(没法打开计数机.上的服务控制管理器,拒绝访问等错误)class
六、新建bat文件(卸载服务.bat)
@ECHO OFF REM The following directory is for .NET1.1 set DOTNETFX=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319 set PATH=%PATH%;%DOTNETFX% cd\ cd "G:\WindowsServiceTest\WindowsServiceTest\bin\Debug" echo 正在卸载 测试服务 echo --------------------------------------------------- InstallUtil /U WindowsServiceTest.exe echo --------------------------------------------------- pause