[Go to].net when the Windows Service installation is complete automatically starts

Source: Internet
Author: User

This article transferred from: http://www.cnblogs.com/hb_cattle/archive/2011/12/04/2275319.html

Given the ease of deployment, we typically create a Windows service written in C # as an installation package. After the service installation is complete, it is very inconvenient to start the service manually for the first time. Looking at some of the information on the Internet, we found that one way to start the service is to invoke the command line in the installation completion event, which is feasible but not perfect. Well, here's a look at how to do a better job of starting the service automatically.

1, rewrite the ProjectInstaller of the Commit method

Using System;Using System.Collections;Using System.Collections.Generic;Using System.ComponentModel;Using System.Configuration.Install;using system.linq; using system.serviceprocess; namespace cleanexpiredsessionseivice{[Runinstaller (true)] public partial class ProjectInstaller: System.Configuration.Install.Installer {public ProjectInstaller () {InitializeComponent (); Span class= "KWRD" >public override void Commit (IDictionary savedstate) {base.commit (savedstate); //auot start service after the installation is completed ServiceController sc = new S Ervicecontroller ( "Cleanexpiredsessionseivice"); if (SC. Status.equals (servicecontrollerstatus.stopped)) {SC. Start (); } } }}

2. Add the custome Action named commit in the service Setup project

Right-click on the Service Setup project and select View-custom Actions from the popup menu

Then right-click on the Commit and select Add Custom Action ... and select Application Folder in the list box that pops up. The final result is as follows:

It is important to note that the second step is necessary, otherwise the service will not start automatically. My personal understanding is that the commit custom action automatically calls ProjectInstaller's Commit method, where the commit custom action plays the role of a caller.

[Go to].net when the Windows Service installation is complete automatically starts

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.