wixwindows-installerinstallationtopshelf

Installing TopShelf with WiX fails due to Admin Rights


So I am trying to install an application built using TopShelf, the application itself runs well and has no problems. The problem I run into is when I try to install the service. The TopShelf service is installed (from an administrator command line) using the myapp.exe install <options> instruction. I have wrapped the instruction in a custom action (see below). This runs, in that I can see a black box pop-up on install. The service fails to install, however. When I run the msi install from an administrator command line, the service installs correctly. I have included all Administrator related parameters in the WiX file (see below also). I am completely out of ideas and in need of help, can anyone see anything in the WiX files or does anyone have any idea what is preventing the service from installing?

What I have tried:

Topshelf - Custom Action in Wix Not Executing

Add Coffee and Shake Well - TopShelf

I have also tried wrapping the call to the topshelf app in a separate WiX custom Action project to execute and this also fails for the same reason.

<Product Id="*" Name="PackageName"
         Language="1033"
         Version="1.0.0.0"
         Manufacturer="Manufacturer"
         UpgradeCode="e7780903-3cf9-4ecc-b65a-45bc18b500df">
  <Package InstallerVersion="200" 
           Compressed="yes" 
           InstallScope="perMachine"  
           InstallPrivileges="elevated" 
           Platform="x64" />

  <Property Id="MSIUSEREALADMINDETECTION" Value="1" />

  <MajorUpgrade AllowSameVersionUpgrades="yes"
              DowngradeErrorMessage="A newer version of [ProductName] is already installed." 
              Schedule="afterInstallInitialize" />
  <MediaTemplate  EmbedCab="yes"/>

  <Feature Id="ProductFeature" Title="FeatureName" Level="1">
    <ComponentGroupRef Id="ProductComponents" />
  </Feature>

  <CustomAction Id="InstallService" 
                FileKey="MyApp.exe" 
                ExeCommand="install" 
                Impersonate="yes"
                Execute="immediate" />
  <CustomAction Id="StopService" 
                FileKey="MyApp.exe" 
                ExeCommand="stop"
                Execute="immediate"  />
  <CustomAction Id="UninstallService" 
                FileKey="MyApp.exe" 
                ExeCommand="uninstall"
                Execute="immediate"  />

  <InstallExecuteSequence>
    <Custom Action="InstallService" After="InstallFinalize" >
      NOT Installed AND NOT REMOVE
    </Custom>
    <Custom Action="StopService" After="InstallInitialize" >
      (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
    </Custom>
    <Custom Action="UninstallService" After="StopService">
      (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
    </Custom>
  </InstallExecuteSequence>
</Product>

Solution

  • There are a couple of problems with your custom actions. One is that the InstallService CA is immediate which means 1) It's before the files are installed and 2) it won't run with elevation. It needs to be deferred and before InstallFinalize.

    If this is just an ordinary Windows service, then you should use a ServiceInstall node to install it (and uninstall it) as well as ServiceControl to stop, start, and delete it.