Wix - How to install multiple windows services with one executable?

前端 未结 4 878
面向向阳花
面向向阳花 2021-02-11 04:02

I\'m trying to install multiple windows services with the same executable, but WiX doesn\'t like the same name attributes in the two file tags. I have tried changing the names o

相关标签:
4条回答
  • 2021-02-11 04:41
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- The name of the product -->
    <?define Service1Name = "Test Service1" ?>
    <?define Service2Name = "Test Service2" ?>
    <!-- The description of the product -->
    <?define Service1Description = "Test Service1 that logs dummy text on an interval to a text file." ?>
    <?define Service2Description = "Test Service2 that logs dummy text on an interval to a text file." ?>
    <!-- The manufacturer, for setup package publisher and folder info -->
    <?define Manufacturer = "Your Company" ?>
    <!-- The version number of this setup package-->
    <?define Version = "1.0.1" ?>
    <!-- UpgradeCode must be unique and not changed once the first version of the program is installed. -->
    <?define UpgradeCode = "{1240E0CD-B3D2-44A7-B064-11B3C0709D69}" ?>
    
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
      <Product Id="*" Name="$(var.Service1Name)" Manufacturer="$(var.Manufacturer)" UpgradeCode="$(var.UpgradeCode)" Version="$(var.Version)" Language="1033">
        <!-- Create a folder inside Your Company called Test Service -->
        <Package InstallerVersion="300" Compressed="yes"/>
        <!-- Create a folder inside Your Company called Test Service -->
        <Media Id="1" Cabinet="TestService.cab" EmbedCab="yes" />
        <!-- Allow upgrades and prevent downgrades -->
        <MajorUpgrade DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit." />
        <!-- Define the directory structure -->
        <Directory Id="TARGETDIR" Name="SourceDir">
          <Directory Id="ProgramFilesFolder">
            <!-- Create a folder inside program files called Your Company -->
            <Directory Id="ROOTDIRECTORY" Name="$(var.Manufacturer)">
              <!-- Create a folder inside Your Company called Test Service -->
              <Directory Id="INSTALLFOLDER" Name="$(var.Service1Name)" />
            </Directory>
          </Directory>
        </Directory>
        <!-- The files inside this DirectoryRef are linked to the Test Service directory via INSTALLFOLDER -->
        <DirectoryRef Id="INSTALLFOLDER">
          <!-- Create a single component which is the TestService.exe file -->
          <Component Id="$(var.TestService1.TargetFileName)">
            <!-- Copies the TestService.exe file using the project reference preprocessor variables -->
            <File Id="$(var.TestService1.TargetFileName)" Source="$(var.TestService1.TargetPath)" KeyPath="yes" />
            <!-- Remove all files from the INSTALLFOLDER on uninstall -->
            <RemoveFile Id="RemoveService1" Name="*.*" On="both" />
            <!-- Tell WiX to install the Service -->
            <ServiceInstall Id="Service1Installer"
            Type="ownProcess"
            Name="TestService1"
            DisplayName="$(var.Service1Name)"
            Description="$(var.Service1Description)"
            Start="auto"
            ErrorControl="normal" />
            <!-- Tell WiX to start the Service -->
            <ServiceControl Id="StartService1" Start="install" Stop="both" Remove="uninstall" Name="TestService1" Wait="yes" />
          </Component>
          <!-- Create a single component which is the TestService.exe file -->
          <Component Id="$(var.TestService2.TargetFileName)">
            <!-- Copies the TestService.exe file using the project reference preprocessor variables -->
            <File Id="$(var.TestService2.TargetFileName)" Source="$(var.TestService2.TargetPath)" KeyPath="yes" />
            <!-- Remove all files from the INSTALLFOLDER on uninstall -->
            <RemoveFile Id="RemoveService2" Name="*.*" On="both" />
            <!-- Tell WiX to install the Service -->
            <ServiceInstall Id="Service2Installer"
            Type="ownProcess"
            Name="TestService2"
            DisplayName="$(var.Service2Name)"
            Description="$(var.Service2Description)"
            Start="auto"
            ErrorControl="normal" />
            <!-- Tell WiX to start the Service -->
            <ServiceControl Id="StartService2" Start="install" Stop="both" Remove="uninstall" Name="TestService2" Wait="yes" />
          </Component>
        </DirectoryRef>
        <!-- Tell WiX to install the files -->
        <Feature Id="Feature1" Title="TestService1.Setup" Level="1">
          <ComponentRef Id="$(var.TestService1.TargetFileName)" />
        </Feature>
        <Feature Id="Feature2" Title="TestService2.Setup" Level="1">
          <ComponentRef Id="$(var.TestService2.TargetFileName)" />
        </Feature>
      </Product>
    </Wix>
    
    0 讨论(0)
  • 2021-02-11 04:51

    A component can belong to more than one feature. Create a single component for your service, then multiple features: each feature has a ComponentRef to the one service component and whatever other references it needs.

    0 讨论(0)
  • 2021-02-11 04:56

    In one of my projects, I have 2 services inside of one executable. So for both services in my exe, I have the following in my wix setup. Hope this helps.

      <Component Id="MyScheduler" Guid="{SOMEGUID}">
        <File Id="MySchedulerEXE" Name="MyScheduler.exe" Source="MyScheduler.exe" KeyPath="yes" />
    
        <ServiceInstall Id="FirstService" Type="ownProcess" Vital="yes" Name="First Service" DisplayName="First Service" Description="First Service" Start="auto" Account="NT AUTHORITY\LocalService" Interactive="no" ErrorControl="ignore" />
        <ServiceControl Id="StartFirstService" Name="First Service" Start="install" Wait="no" />
        <ServiceControl Id="StopFirstService" Name="First Service" Stop="both" Wait="yes" Remove="uninstall" />
    
        <ServiceInstall Id="SecondService" Type="ownProcess" Vital="yes" Name="Second Service" DisplayName="Second Service" Description="Second Service" Start="auto" Account="NT AUTHORITY\LocalService" Interactive="no" ErrorControl="ignore" />
        <ServiceControl Id="StartSecondService" Name="Second Service" Start="install" Wait="no" />
        <ServiceControl Id="StopSecondService" Name="Second Service" Stop="both" Wait="yes" Remove="uninstall" />
    
      </Component>
    
    0 讨论(0)
  • 2021-02-11 04:56

    Finally found the solution. for multple services in same exe, you have to set Type="shareProcess" in ServiceInstall element and both the services will work just fine. I found this out by installing my service using "InstallUtil" and compared the registry structure. "InstallUtil" set type to ownProcess, so i changed mine in installer too and that worked like a charm.

    <Component Id="MyScheduler" Guid="{SOMEGUID}">
    <File Id="MySchedulerEXE" Name="MyScheduler.exe" Source="MyScheduler.exe" KeyPath="yes" />
    
        <ServiceInstall Id="FirstService" Type="shareProcess" Vital="yes" Name="First Service" DisplayName="First Service" Description="First Service" Start="auto" Account="NT AUTHORITY\LocalService" Interactive="no" ErrorControl="ignore" />
        <ServiceControl Id="StartFirstService" Name="First Service" Start="install" Wait="no" />
        <ServiceControl Id="StopFirstService" Name="First Service" Stop="both" Wait="yes" Remove="uninstall" />
    
        <ServiceInstall Id="SecondService" Type="shareProcess" Vital="yes" Name="Second Service" DisplayName="Second Service" Description="Second Service" Start="auto" Account="NT AUTHORITY\LocalService" Interactive="no" ErrorControl="ignore" />
        <ServiceControl Id="StartSecondService" Name="Second Service" Start="install" Wait="no" />
        <ServiceControl Id="StopSecondService" Name="Second Service" Stop="both" Wait="yes" Remove="uninstall" />
    
      </Component>
    
    0 讨论(0)
提交回复
热议问题