Aldus-Monitor
Aldus-Monitor

Reputation: 91

How do I create an Icon for my non-advertised application in Windows using WiX?

We have recently removed the Advertised property to our installation since all the icon was standard ones (generic/blank) after installing. Now we use this kind of code:

<DirectoryRef Id="MyAppShortcutFolder">
    <Component Id="MyAppShortcuts" DiskId="1" Guid="MyGuid">
        <CreateFolder />
        <RegistryKey Action="createAndRemoveOnUninstall" Root="HKCU" Key="$(var.MyAppRegKey)\Shortcuts">
            <RegistryValue Name="ClientShortcuts" Value="yes" Type="string" KeyPath="yes" />
        </RegistryKey>
        <Shortcut Id="MyAppShortcut" Directory="MyAppShortcutFolder" 
            Name="!(loc.ShortcutMyAppName)"
            WorkingDirectory="MYAPPINSTALLDIR"
            Target="[MYAPPINSTALLDIR]MyApp.exe"
            Arguments='xxx"'
            Icon="ARPPRODUCTICON.exe" />
        <RemoveFolder Id='RmdirClientShortcutFolder' Directory='MyAppShortcutFolder' On='uninstall' />
    </Component>
...
<Icon Id="ARPPRODUCTICON.exe" SourceFile="$(var.MyAppBasePath)\ICO\MyAppShortcut.ico" />

This produce a shortcut that points to an icon installed somewhere like "%systemroot%/A-GUID-Here/ARPPRODUCTICON.exe". This work fine as long as the shortcut is not copied to the desktop. If the user does this (very common actually) and then later installs a new version of our software (probably a "major" update) the old shortcut icon is uninstalled and a new GUID is created for the new shortcut icon. This makes the (old) desktop shortcut lose its icon.

What we really want is to point out the icon from the built in resource of the MyApp.exe. If this is not possible we would like the shortcut icon to reference a permanent location so that the old shortcut still works after an upgrade. We have maybe 10 shortcuts in the install. We could create a special resource DLL/EXE for just storing the ICON resource if necessary. But how to we make the short point out a "locally" installed file instead of %systemroot%?

We use Wix 3.5. We must support Windows XP/2003.

Regards Aldus

Upvotes: 1

Views: 419

Answers (2)

helb
helb

Reputation: 7773

If you do not specify the Icon attribute for the Shortcut element, the shortcut is created with the first icon found in the target exe file.

I am on Windows 10 and using WiX 3.10 with shortcuts that have advertised="yes" but I disable advertising them with:

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

Also see this answer.

Upvotes: 0

Ian Crane
Ian Crane

Reputation: 21

A permanent location for the ico file won't fix another problem in that the shortcut the user copied to the desktop will still point at the wrong EXE file.

One approach I've used in the past to maintain a stable program shortcut to a file that moves around or changes names is to create a very small stub EXE under your main app folder for the shortcut to point at. When run, the stub uses runtime logic to find the real EXE and then shells it. For example, in your case, you might write a registry entry with the GUID so the stub knows where to find the EXE. If your other EXE is large or slow to load / initialize, then you can add a splash screen to your stub and get a quicker UI response experience for the user at the same time.

Upvotes: 1

Related Questions