(1) create a Windows ServiceProgramSelect the debug/release typeAnycpu(Especially for 64-bit machines)
(2) When you add an installer, two components are generated, such as serviceprocessinstaller1 and serviceinstaller1.
(3) When adding an installer for the service,The name attribute of the installer (such as serviceinstaller1) must be consistent with the name attribute of the service.
(4)The account attribute of serviceprocessinstaller1 must be set to LocalSystem
(5) When installing the service,Run the viusial studio command line tool as an administrator for installation..
Command for installing the service:
Installutil "program address"
(For example, installutil "D:/users/spang/documents/visualstudio2010/projects/windowsservice1/windowsservice1/bin/debug/windowsservice1.exe ")
Command to uninstall the service:
Installutil "program address"/u
(For example, installutil "D:/users/spang/documents/visualstudio2010/projects/windowsservice1/windowsservice1/bin/debug/windowsservice1.exe"/U)
(6) start the service after installation, you can choose my mycomputer> Manage> System Tools> eventviewer> Windows logs> application (my computer> Management> Event Viewer> Windows Log> Application program) view service logs.
(7) possible errors when using commands:
I. An attempt was made to load a program withan incorrect format. Solution: Step 1
II. The Install failed, and the roll back hasbeen timed med. Solution: Step 4
The simplest Windows ServiceCodeExample (VB. NET ):
C # code is similar to this
Public Class Service1
Protected Overrides Sub Onstart ( Byval ARGs () As String )
' Add code here to start your service. This method shocould set things
' In motion so your service can do its work.
EventLog. writeentry ( " Start Service " )
End sub
Protected Overrides Sub Onstop ()
' Add code here to perform any tear-down necessary to stop your service.
End sub
End Class