There are two ways of doing this:
1. In VS2010 and the following versions
- First open the service main program file in Design view, right-click to select "Add Installer"
- Set the appropriate properties after adding ProjectInstaller
The general settings are as follows:
To set the properties of the ServiceInstaller1 component:
1) ServiceName = Service Name
2) StartType = Automatic, i.e. automatic
Setting the properties of a serviceProcessInstaller1 component
1) account = LocalSystem, accounts are generally set to local system
- On the solution, right-select Add-New project, adding a Setup project
Finally compile the solution, in the Setup Project Project Debug directory can find the service installation program, directly click Install.
2. In VS2012 and later
- Also need to add installer, the process ibid.
Add a text file to the project, rename it to Install.bat, and edit the contents of the file as follows:
@echo off
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe-i "WindowsService1.exe"
@pause
Add a text file to the project, rename it to Uninstall.bat, and edit the contents of the file as follows
@echo off
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe-u "WindowsService1.exe"
@pause
- After compiling, copy the debug files to the directory you want to install, click Install.bat to complete the installation (server 2008 and above servers need to run in administration mode)
You may be prompted to not find WindowsService1.exe when you run Install.bat, you need to specify the absolute path of WindowService1.exe in Install.bat
Windows Service Installation