1

We recently changed the name of our application from let's say test1app to test2app. So now when our customers update my application from the old version to this new one I want the shortcuts for test1app to get removed because I have already removed all the files with that name(I removed them with RemoveFile and RemoveFolder).

Is it possible to remove .lnk files with RemoveFile as well? I have one shortcut on the desktop and one in the program files.

I have tried to remove the .lnk file with remove file but it does not get removed. I even tried to add a plain .txt file and remove it from the desktop but it does not get removed either so maybe I am calling the wrong Dictionary or something?

This is a snipped from my code:

 `<Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramMenuFolder">
          <Directory Id="ApplicationStartMenuDirectory" Name="Test2"/>
      </Directory>
      <Directory Id="DesktopFolder" Name="Desktop" />
 </Directory>`

`<DirectoryRef Id="ProgramMenuFolder">
    <Component Id="delete_test1_shortcuts" Guid="*">`

//Here I am trying to remove the shortcut from the Application start menu dir

`<RemoveFile Directory="ApplicationStartMenuDirectory" Id="test1.lnk_shortcut" Name="test1.lnk" On="install" />
        <RegistryValue Root="HKCU" Key="Software\Company\test1" Name="installed" Type="integer" Value="1" KeyPath="yes"/>`

//Here I am trying to remove the desktop shortcut

        `<RemoveFile Directory="DesktopFolder" Id="desktop_test1.lnk" Name="test1.lnk" On="install" />
    </Component>`

`</DirectoryRef>`

//then reference the component 

`<Feature Id="MainApplication" Title="testapp" Level="1">
    <ComponentRef Id="delete_test1_shortcuts"/>
</Feature>`

The goal is that when the customers upgrade their version that the all the test1 shortcuts get removed so they only see the test2 shortcuts on install.

Harpa
  • 11
  • 3
  • Does the new EXE file have a new name? Are you live with your new release? If there is a new name, and you are not live you should update the component GUID for the component holding the EXE and the shortcut. This should make MSI remove the shortcut on its own. – Stein Åsmul Sep 03 '19 at 14:27
  • It does have a new name. So since the customers are updating their version it just added test2.exe. So now the customers would have both test1.exe (because it did not get deleted) and test2.exe. I was able to remove the test1.exe file with remove file and remove folder. So at the moment, they do not get the test1.exe but I can not remove the shortcuts to test1.lnk from the desktop and the program folder. Should I have done it differently? Because if I am able to remove the .lnk files for test1 everything is good. But maybe it is not possible to remove .lnk files manually. – Harpa Sep 03 '19 at 17:27
  • I tried to change the GUID of the component that makes the shortcuts, did I understand you correctly that I was supposed to change that GUID? But nothing did change. – Harpa Sep 03 '19 at 17:28
  • If you add the new binary as a new component and give it a new component GUID, and then remove the old binary component - with the old component GUID - you should see it work properly on upgrade scenarios. Test on a clean virtual. This is due to MSI's reference counting. The old component will be uninstalled - with all its content - including the shortcut - auto-magically, and the new one installed. Crucial that you do everything correctly though. – Stein Åsmul Sep 03 '19 at 18:14
  • So should I not remove the old .exe files manually like I have done but just change the guid of component containing the .exe file and also the guid of the component containing the shortcuts and renaming the files correctly? Do I understand you correctly? – Harpa Sep 03 '19 at 20:18
  • I quickly added a description below. Not great, I will look back later or tomorrow. – Stein Åsmul Sep 03 '19 at 20:34
  • 1
    How did you create the shortcut originally? Was it part of a component? Did that component contain the binary you launch? – Stein Åsmul Sep 04 '19 at 17:45
  • Was the previous installation done with Windows Installer? If so, "update my application" is really upgrading a "Product" installation as a Major Upgrade, Minor Upgrade, etc, or a new product who's installer uninstalls related products. (What you might call an application is just components belonging to one or more products-versions.) – Tom Blodget Sep 06 '19 at 22:52

2 Answers2

0

Please try this:

  1. Remove the old component containing the old binary (EXE) AND the shortcut (and whatever other content is there).
  2. Add a new component with the new binary (EXE) AND the new shortcut with the new name (important). Make sure it has a new component GUID.

This is all related to how component reference counting is done in MSI: Change my component GUID in wix?

Essentially: there is a 1:1 match between absolute installation path and the component GUID. If one changes, change the other and the older component will be uninstalled as a whole entity: all settings will be removed. There should be no overlapping resources between the components (not the same name shortcut for example).

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • When you say remove, do you just mean to remove the code from the file (the component that makes those files) or do you mean that I should use remove file and remove folder to remove these files? – Harpa Sep 04 '19 at 14:10
  • You remove the component, or just give it a new component GUID (which is in practice the same as deleting the existing component and making a new one). Please do read: [Change my component GUID in wix?](https://stackoverflow.com/questions/1405100/change-my-component-guid-in-wix/1422121#1422121). – Stein Åsmul Sep 04 '19 at 15:31
0

I am not sure, why it did not work for you, I just had to do the same and the code below worked for me (some properties omitted for clarity). Wix 3.11.2

<DirectoryRef Id="ProgramMenuFolder">
  <Component Id="StartMenuShortcut" Guid="{guid}">
    <Shortcut Id="StartMenuShortcut"
              Name="Myapp"
              WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
    <!-- added the line below -->
    <RemoveFile Id="RemoveOldStartMenuShortcut" On="install" Name="MyOldShortcut.lnk"/>
  </Component>
</DirectoryRef>

<DirectoryRef Id="DesktopFolder">
  <Component Id="DesktopShortcut" Guid="{guid}">
    <Shortcut Id="DesktopShortcut"
              Name="Myapp"
              WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
    <!-- added the line below -->
    <RemoveFile Id="RemoveOldDesktopShortcut" On="install" Name="MyOldShortcut.lnk"/>
  </Component>
</DirectoryRef>
Evgeny
  • 3,320
  • 7
  • 39
  • 50