Making installation packages with WiX (3)

Source: Internet
Author: User

Using WiX to install the service is simple. It takes just a few words to get there. After we create the good one Windows service. We create a file in the project Service.wxs to install the service, and edit the code as follows:

<?xml version= "1.0" encoding= "UTF-8"?><Wix xmlns="Http://schemas.microsoft.com/wix/2006/wi">    <Fragment>    <Component Id= "productc" Guid=" De8dd064-c440-4e82-80d7-d05c98753daf " Directory=" PRODUCTC ">      <file  Id  = "Productcservice"  source  =  "$ (var. Productc.targetdir) ProductC.exe "/>       <serviceinstall  Id  = "Productcserviceinstaller"  type< /span>= "ownprocess"  name  = "PRODUCTC"  displayname  =" PRODUCTC " description  =" Pr                      ODUCTC " start  =" auto "                      account  = "LocalSystem"  errorcontrol  = "ignore" ;         <serviceconfig delayedautostart="No" oninstall="yes" />       </serviceinstall>      <servicecontrol Id="Productcservicecontrol"Start="Install" Stop= "both"Remove="Uninstall"Name="PRODUCTC"  Wait="yes" />                                                                                                                  </Component>  </Fragment></Wix>

In the example above we have installed a ProductC service-to-system named. And added a ServiceControl way to control his behavior. Then we associate this component to a feature of the product and the service will be installed when the product is installed.

However, in some cases services implemented with Topshelf, we cannot install with WiX. At this point we need to add a ServiceInstall.cs file to the service's project and add the following code.

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Configuration.Install;usingSystem.Linq;usingSystem.ServiceProcess;usingSystem.Text;usingSystem.threading.tasks;namespace ditronicshisvr{[Runinstaller (true)] Public classHardwareserviceinstaller:installer { PublicServiceInstaller ServiceInstaller; PublicServiceProcessInstaller ServiceProcessInstaller; Public Hardwareserviceinstaller()                { This.                InitializeComponent (); }Private void InitializeComponent() {ServiceInstaller =NewServiceInstaller (); ServiceProcessInstaller =NewServiceProcessInstaller (); This.                        Serviceprocessinstaller.account = Serviceaccount.localservice; Serviceinstaller.description ="Service used to interface with Bill validators."; Serviceinstaller.displayname ="Ditronics HI Server"; Serviceinstaller.servicename ="Ditronicshisvr"; This. Installers.addrange (NewInstaller[] { This. ServiceProcessInstaller, This.                ServiceInstaller}); }        }}

After adding the above code, we can use WiX to install the service properly. Service ServiceName and description in the above code must be consistent with the ServiceName and description in WiX. Otherwise there will be a bug that the service is installed and cannot be started.

Making installation packages with WiX (3)

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.