How to use Windows service?

Source: Internet
Author: User

(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

 

    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.