CustomAction in Wix not executing
Asked Answered
B

2

7

So I'm creating my first Wix project and I seem to be having a problem executing a custom action. I'm not sure that it's being included in the msi and I'm not quite sure what I'm doing wrong. The following is my Wix file:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="ExactaDynamicManifest" Language="1033" Version="1.0.0.0" Manufacturer="Bastian Software Solutions" UpgradeCode="274ff2d9-e291-4706-a8db-ce80ccd91538">
      <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"/>

      <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
      <MediaTemplate />

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

      <Icon Id="exacta.ico" SourceFile="icons\exacta.ico"/>
      <Property Id="ARPPRODUCTICON" Value="exacta.ico" />

    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
        <Directory Id="ExactaFolder" Name ="Exacta">
                  <Directory Id="INSTALLFOLDER" Name="ExactaExactaDynamicManifest" />
        </Directory>
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
      <CustomAction Id="InstallService" FileKey="ExactaDynamicManifest.exe" ExeCommand="install"/>
      <InstallExecuteSequence>
        <Custom Action="InstallService" After="InstallFinalize"/>
      </InstallExecuteSequence>
    </Fragment>
</Wix>

The last fragment contains my custom action which what I hoped would do is the following on the command line after all files have been placed in the directory:

ExactaDynamicManifest.exe install

One thing to note is that exe is actually coming from a ComponentGroupRef defined above. Not sure if this is a problem or not but thought I'd mention it. Any help would be appreciated.

Bunn answered 17/1, 2014 at 19:37 Comment(1)
Check my answer here, it should help you: https://mcmap.net/q/104318/-wix-how-to-run-exe-files-after-installation-from-installed-directoryBriefs
B
8

I finally got something that is working. My initial problem of the CustomAction not loading seemed to be due to it being in a different <fragment>. I consolidated all of the code into a single fragment and it seemed to run.

After battling with user permissions etc I finally ended up with this solution:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="ExactaDynamicManifest" Language="1033" Version="1.0.0.0" Manufacturer="Bastian Software Solutions" UpgradeCode="274ff2d9-e291-4706-a8db-ce80ccd91538">
      <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"/>

      <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
      <MediaTemplate />

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

      <Icon Id="exacta.ico" SourceFile="icons\exacta.ico"/>
      <Property Id="ARPPRODUCTICON" Value="exacta.ico" />

    </Product>

    <Fragment>
      <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
          <Directory Id="ExactaFolder" Name ="Exacta">
            <Directory Id="INSTALLFOLDER" Name="ExactaExactaDynamicManifest" />
          </Directory>
        </Directory>
      </Directory>

      <CustomAction Id="RunTopShelfServiceInstall" Directory="INSTALLFOLDER" Execute="deferred" Return="ignore" Impersonate="no" ExeCommand="[INSTALLFOLDER]ExactaDynamicManifest.exe install"/>
      <CustomAction Id="RunTopShelfServiceUninstall" Directory="INSTALLFOLDER" Execute="deferred" Return="ignore" Impersonate="no" ExeCommand="[INSTALLFOLDER]ExactaDynamicManifest.exe uninstall"/>

      <InstallExecuteSequence>
        <Custom Action="RunTopShelfServiceInstall" After="InstallFiles">
          NOT Installed
        </Custom>
        <Custom Action="RunTopShelfServiceUninstall" After='InstallInitialize'>
          (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
        </Custom>
      </InstallExecuteSequence>

    </Fragment>
</Wix>
Bunn answered 21/1, 2014 at 21:44 Comment(2)
You can also further decouple your service.exe's name from your wix code via: ExeCommand="[INSTALLFOLDER]$(var.YourServiceProjectName.TargetName) install" assuming you have added the project as a reference to your wix project.Parimutuel
You saved my ass, with that! ;)Ary
J
0
  1. Are you going to register a service using a custom action? You also have to handle uninstall, repair actions. It's much simpler to use standard MSI feature to install services: http://wixtoolset.org/documentation/manual/v3/xsd/wix/serviceinstall.html

  2. If you want to use custom actions for this purpose and UAC is enabled your service won't be installed due to permissions. You have to use deferred and not impersonated custom action scheduled before InstallFinalize (after InstallFinalize custom actions can't be scheduled).

Jeggar answered 18/1, 2014 at 11:14 Comment(6)
Yes I'm installing the service via a CustomAction. I'm not using the standard service install in Wix because it's NOT a standard service. I'm using a framework called Topshelf (topshelf-project.com). Also I do plan on handling uninstall and repair but first things first ... I need to install the service.Bunn
We also use Topshelf for our services, it does not contradict using standard MSI features. If your service does something specific during installation, you can do it during the first start.Jeggar
That's interesting because most of the articles I've read online that refer to installing Topshelf services recommend using CustomActions to do so. I have seen an article that says to create an Installer class like a normal windows service but at that point I question why I'm even using Topshelf. So are you creating this installer class to be able to utilize the standard functionality in Wix?Bunn
Wix can be used to install topshelf service. You just have to make sure that service name in wix file exactly match service name in call to topshelf's SetServiceName().Massengale
@VastlyRedskin if you got it working why not post a simple example with both the topshelft setup code and the wix source?Dichlamydeous
@Dichlamydeous In case anyone is still wondering, this worked for me: Suppose you have something like this in your wix config: <ServiceInstall Id="SeviceInstall" Name="AwesomeService" Type="ownProcess" Start="auto" Account="LocalSystem" ErrorControl="normal"> </ServiceInstall> Then in your topshelf the service name must be exactlythe same: configure.SetServiceName("AwesomeService");Fourfold

© 2022 - 2024 — McMap. All rights reserved.