Wix burn doesn't allow to remove file
Asked Answered
E

2

0

I'm creating a bootsrapper and I want to remove links that are created during installation. So I write following step:

<Chain>
  ...
  <ExePackage Id="removelnk" Cache="no" SourceFile="run.bat" InstallCommand="del &quot;C:\Users\Public\Desktop\Parity UI.lnk&quot;" />
</Chain>

Where run.bat is simply %* which allows to run arbitrary code as described here.

However, it doesn't work:

[19EC:0E2C][2018-06-16T18:32:27]i301: Applying execute package: removelnk, action: Install, path: C:\ProgramData\Package Cache\1608BB75347CD8C40187E5F3C0A969ED73A98D51\run.bat, arguments: '"C:\ProgramData\Package Cache\1608BB75347CD8C40187E5F3C0A969ED73A98D51\run.bat" del "C:\Users\Public\Desktop\Parity UI.lnk"'
[19EC:0E2C][2018-06-16T18:32:27]e000: Error 0x80070001: Process returned error: 0x1
[19EC:0E2C][2018-06-16T18:32:27]e000: Error 0x80070001: Failed to execute EXE package.
[0AE4:2B94][2018-06-16T18:32:27]e000: Error 0x80070001: Failed to configure per-machine EXE package.
[0AE4:2B94][2018-06-16T18:32:27]i319: Applied execute package: removelnk, result: 0x80070001, restart: None
[0AE4:2B94][2018-06-16T18:32:27]e000: Error 0x80070001: Failed to execute EXE package.

If I execute this command from log in my cmd then it works as expected. It even works without admin privileges.

What's wrong here?

Earldom answered 16/6, 2018 at 15:39 Comment(1)
See which Feature(s) in the MSI has the Component with the shortcut. (Try dark.exe or orca or InstEdit) If you can do without that feature, just exclude it during installation. Otherwise do as @Stein suggests.Moise
K
5

Creating a Transform: You can use a transform to modify any MSI file - a very common use for a transform is to remove such shortcuts. You should be able to apply that transform on the command line specified in your bootstrapper - though I have never tried this with WiX bootstrappers.

Transforms are "little database fragments" that are applied to the original MSI. It changes the MSI file in memory and you can pretty much change whatever you want. You can create transforms with Orca or an equivalent free tool. Commercial tools - such as Advanced Installer - can also be used of course. In fact they have a nice little video showing the process (towards the bottom).

There is a long explanation of transforms (among other things) here: How to make better use of MSI files.


Applying a Transform: You apply transforms via the Transforms property during installation.

Quick Sample Command Line:

msiexec.exe /I "My.msi" /QN /L*V "C:\My.log" TRANSFORMS="C:\1031.mst;C:\My.mst"

Quick Parameter Explanation:

/I = run installation sequence
/QN = run completely silently
/L*V "C:\My.log"= verbose logging
TRANSFORMS="C:\1031.mst;C:\My.mst" = Apply transforms 1031.mst and My.mst.

Burn Bundle Details: I have not tried applying a transform in a Burn bundle (so I should have the sense not to answer), but the MsiPackage element is what you need I believe. I found this rather complicated sample of a Burn bundle source file - perhaps it is worth a look? It seems the magic is in the MsiProperty child element for the MsiPackage element.


UPDATE:

Burn Hello-World Style Example: Finally got to run a quick test on a Windows computer (was on a Linux one). Here is how you can apply a transform via Burn (minimal sample, just intended to show the basics, not pretending to be good markup).

Just inlining the warning: I hear some rumors that the application of the transform in this way might not work in all cases - such as repair. Please test thoroughly. It worked for my test. Also test upgrade scenarios (major upgrade for example).

This will apply the transform ShortcutDesktop.mst to the original MSI ShortcutDesktop.msi:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">

    <!-- Maybe generate yourself an Upgrade-GUID here: https://www.guidgenerator.com/ -->

    <Bundle Name="MyCoolTestApp" Version="1.0.0.0" Manufacturer="Someone"
            UpgradeCode="PUT-GUID-HERE">        

    <BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" />

        <Chain>
            <MsiPackage SourceFile="ShortcutDesktop.msi">
                <MsiProperty Name="TRANSFORMS" Value="ShortcutDesktop.mst" />
            </MsiPackage>
        </Chain>

    </Bundle>

</Wix>

To build the Burn bundle BurnTest.wxs above:

set SetupName=BurnTest

candle.exe %SetupName%.wxs -ext WixBalExtension >> %SetupName%.log
light.exe %SetupName%.wixobj -ext WixBalExtension >> %SetupName%.log

And a link to a better Burn example on github:

Knap answered 16/6, 2018 at 22:47 Comment(2)
I didn't try it yet, but it looks really promising. Great answer, thank youEarldom
I hear some rumors that the application of the transform in this way might not work in all cases - such as repair. Please test thoroughly. It worked for my test.Solidago
D
1

Burn doesn't support batch files. Everything that modifies the machine should be done in a package.

Denature answered 16/6, 2018 at 16:15 Comment(3)
So burn make me to create an installer which single function is delete some file on machine?Earldom
Well, I'd like to do it if I could, but it's not my installer which I'm crating my bootstrapper over. I wonder if I can automatically delete this shortcut that is created by another MSI.Earldom
@Alex What you are proposing is to damage the installed components. Your change would likely be undone by a "repair".Moise

© 2022 - 2024 — McMap. All rights reserved.