1. Add WindowsService project
2. Click on the view code in the design interface. Define the executable body
2.1 and Start() in Server.Start(). If there is an infinite loop body, use Thread or Timer, otherwise it will start all the time and then start. Failure, the actual program is running, can not be closed
2.2, use Thread, not actively released in Stop, Thread will continue to execute, about 30 seconds after the service is stopped, release release
2.3, use Thread, actively release in Stop, Thread will stop in the service Stop immediately (recommended)
2.4, use Timer, not actively released in Stop, will be released when the service is stopped, of course, recommended manual release, compare specifications
3, add the installation program in the design interface right
4, change the verification mode of the installation program For LocalSysytem

this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
5, do not need ClickOnce signature, compile
6, use exe exe program

Suppose the path to this program is @path

7, installation services

New cmd script (no BOMUTF8 encoding), must be run in admin mode

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe “@path”
8, uninstall service

New cmd script (no BOMUTF8 encoding), must be run in admin mode

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /u “@path”