1. Create a new Windows Service project
2. Edit the business code
I'm just writing a 2-sentence test code for the recorded text.
usingSystem;usingSystem.IO;usingsystem.serviceprocess;namespacewindowsservice{ Public Partial classService:servicebase { PublicService () {InitializeComponent (); } protected Override voidOnStart (string[] args) {System.IO.File.AppendAllText (Path.Combine (AppDomain.CurrentDomain.BaseDirectory,"Log.txt"),string. Format ("{0} I'm starting.", DateTime.Now)); } protected Override voidOnStop () {System.IO.File.AppendAllText (Path.Combine (AppDomain.CurrentDomain.BaseDirectory,"Log.txt"),string. Format ("{0} I'm stopping.", DateTime.Now)); } }}
View Code
3. Add the Installer
4. Setting the ProjectInstaller property
These 2 can be set as shown above
Below to import the bat culture separately
Installutil.bat (Installation)
WindowsService.exe Program Name
Testservice the service name set above ServiceName
InstallUtil windowsservice.exenet Start Testservicepause
Startservice.bat (Start service)
net start Testservicepause
Stopservice.bat (stop service)
net stop Testservicepause
Unintall.bat (uninstall)
InstallUtil/u windowsservice.exepause
Put this 4 file under the root directory and set it to always replicate.
There is also a file InstallUtil.exe also need to be set to always copy
Finish these operations and then generate some programs to the bin directory by double-clicking the Installutil.bat installation
Download Demo
Ext.: http://www.cnblogs.com/liuxiaoji/p/4779024.html
Windows Service Deployment