Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

windows installer - Wix burn doesn't allow to remove file

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:UsersPublicDesktopParity 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:ProgramDataPackage Cache1608BB75347CD8C40187E5F3C0A969ED73A98D51
un.bat, arguments: '"C:ProgramDataPackage Cache1608BB75347CD8C40187E5F3C0A969ED73A98D51
un.bat" del "C:UsersPublicDesktopParity 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...