Environment: vs2013,win7
Reference:
Fast setup and debugging of Windows Services (C # plots)
. NET implements two methods for automatic startup after Windows Service installation is complete
C # build Windows Service Packager
1. New project Windows Service project.
2, the service automatically starts after installation.
Right-click Add Installer
To set some properties of the service. Set the account type for the running service to be a local account.
Set the service name and set startup mode to start automatically.
Note The Display name: is the name of the service that is set to see. In the computer "management" service, see this.
Service Name: Is the setting of the actual services names. This is what you see in the Window Task Manager.
What you see in the Task Manager process is the name of the Windows Service project.
In the ProjectInstaller class, override the parent class commit method
The code is as follows: note the name, which, like the name of the Windows service setting, is set in the ServiceInstaller1 right-click Property
1[Runinstaller (true)]2 Public Partial classProjectInstaller:System.Configuration.Install.Installer3 {4 PublicProjectInstaller ()5 {6 InitializeComponent ();7 }8 9 Public Override voidCommit (IDictionary savedstate)Ten { One Base. Commit (savedstate); AServiceController sc =NewServiceController ("Service1"); - if(SC. Status.equals (servicecontrollerstatus.stopped)) - { the SC. Start (); - } - } -}
3, packaged as EXE files.
VS2013 does not have a packaged project by default and requires download and installation.
Microsoft Visual Studio Installer Projects
After the installation is complete, the solution right-adds a new project, Setup project
ADD, project output
Select your Windows Service project
Right-click on the package item, view, custom action
Each adds a custom action
Final effect
Finally, the installation package can be generated, in the bin directory in debug
After the installation is complete, you can see the service.
Windows serivce Service implementation process and packaging installation