Wix recreate deleted shortcut when reinstalling - wix

I'm learning about shortcuts in Wix and have managed to create shortcuts on the desktop.
If I delete the shortcut and then run the installer again I would like the shortcut to be created again.
How can this behavior be achieved with Wix?
I have created shortcuts both with
<File Id="TestX.exe" Name="TestX.exe" Source="$(var.TestX_TargetDir)TestX.exe">
<Shortcut Id="desktopIcon" Directory="DesktopFolder" Name="TestX" WorkingDirectory='INSTALLFOLDER' Icon="IconTestX.exe" IconIndex="0" Advertise="yes" />
</File>
and
<Fragment>
<DirectoryRef Id="DesktopFolder">
<Component Id="DesktopShortcut"
Guid="1E0D1741-57F0-4E22-89FC-4A189E2BB7E0">
<Shortcut Id="desktopSC"
Name="MyProduct"
Description="MyProduct description"
Target="[INSTALLFOLDER]TestX.exe"
Icon="IconTestX.exe">
</Shortcut>
<RemoveFolder Id="RemoveDesktopFolder"
Directory="DesktopFolder"
On="uninstall" />
<RegistryValue Root="HKCU"
Key="Software\[Manufacturer]\[ProductName]"
Name="installed"
Type="integer"
Value="1"
KeyPath="yes" />
</Component>
</DirectoryRef>
</Fragment>

I solved this problem by using WixUI_InstallDir in the WixUI library, which added a GUI which includes the option to start a repair.
Links about the WixUI dialog library:
http://wixtoolset.org/documentation/manual/v3/wixui/wixui_dialog_library.html
http://wixtoolset.org/documentation/manual/v3/wixui/dialog_reference/wixui_installdir.html

Related

Set shortcut targetpath Wix

I want to set the shortcut target path in wix for an advertised shortcut
This is the code that creates the shorcut now:
<Component Id="APP_EXE" Directory="INSTALLDIR" DiskId="1" Guid="XXXX-XXXX">
<File Id="AppExe" Name="app.exe" Source="$(var.ComponentSourceDir)\$(var.ExeName)" KeyPath="yes">
<Shortcut Id="desktopShortcut" Advertise="yes" Directory="DesktopFolder" Name="$(var.VersionedName)" WorkingDirectory="INSTALLDIR" Icon="MainIcon.exe" IconIndex="0" />
</File>
</Component>
The target in shortcut properties window is readonly now and it displayes the application name. I cannot change it.
I created a new component where I create the shortcut. I removed the previous one.
<Component Id="APP_EXE" Directory="INSTALLDIR" DiskId="1" Guid="XXXX-XXXX">
<File Id="AppExe" Name="app.exe" Source="$(var.ComponentSourceDir)\$(var.ExeName)" KeyPath="yes">
</File>
</Component>
<Component Id="APP_SHORTCUT" Directory="INSTALLDIR" DiskId="1" Guid="XXXX_XXXXX">
<RegistryValue Root="HKCU" Key="Software\APP\Installer" Name="desktopShortcut" Value="KeyPath" KeyPath="yes" Type="string" />
<Shortcut Id="desktopShortcut" Directory="DesktopFolder" Name="$(var.VersionedName)" WorkingDirectory="INSTALLDIR" Icon="MainIcon.exe" IconIndex="0" Target="[INSTALLDIR]app.exe"/>
</Component>

WiX missing 'Start In' property in desktop shortcut

I am working with WiX from last 5 month with no issues. Recently, i am in need to have "StartIn" property in App Desktop shortcut. By default, its empty.
Here is my full Installer code.
I am working with below code:
<Component Id="myapplication.EXE" DiskId="1" Guid="*">
<File Id="myapplication.EXE" Name="My Application.exe"
Source="D:\My Application\My Application.exe">
<Shortcut Id="desktopShortcut" Directory="DesktopFolder"
Name="My Application" WorkingDirectory="INSTALLDIR"
Icon="DesktopIcon.exe" IconIndex="0"
Description="My Application Description" />
<Shortcut Id="ExeShortcut" Directory="ProgramMenuDir"
Name="My Application" Icon="StartMenuIcon.exe" IconIndex="0" />
</File>
</Component>
But didn't work.
I have also tried adding "Target" property:
<Shortcut Target= "INSTALLDIR" Id="desktopShortcut" Directory="DesktopFolder"
Name="Virtual Sim Center Beta" WorkingDirectory="INSTALLDIR"
Icon="DesktopIcon.exe" IconIndex="0"
Description="My Application Description" />
but getting error message:
The Shortcut/#Target attribute cannot be specified when the Shortcut
element is nested underneath a File element.
This script bellow is working for my WIX:
....
<!-- Desktop Menu -->
<DirectoryRef Id="DesktopFolder">
<Component Id="FooDesktopShortcutMenu" Guid="*">
<Shortcut Id="FooApplicationDesktopShortcut"
Name="Foo Application"
Description="The Foo is Cool!"
Target="[#FooMainApp]"
WorkingDirectory="INSTALLFOLDER"
Directory="DesktopFolder"/>
<RemoveFolder Id="DesktopFolder" On="uninstall"/>
<RegistryValue Root="HKCU" Key="Software\Microsoft\FooApplication"
Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</DirectoryRef>
....
<!-- Tell Wix -->
<Feature Id="ProductFeature" Title="FooSetup" Level="1">
.....
<ComponentRef Id="FooDesktopShortcutMenu"/>
.....
</Feature>
.....
Glytzhkof is right and so is your WiX source - just put it under the Component.
In addition to the answer by #Adiono check whether the 'WorkingDirectory' folder actually contains the 'Target'.
The 'Start in' of my shortcut was blank even when both 'WorkingDirectory' and 'Target' had valid values, but the 'Target' was not present in the 'WorkingDirectory'.
I don't have Wix set up to try this, but you can try to move the Shortcut element up to be nested under the Component element and not the File element. Then set the WorkingFolder attribute. Try something like this.

Program menu shortcut not removed after Major Upgrade

I have this component in my first version:
<ComponentGroup Id="ProgramMenuComponents" Directory="PROGRAMMENUFOLDER">
<Component Id="ApplicationShortcut">
<Shortcut Id="ApplicationStartMenuShortcut" Name="$(var.ProductName)" Icon="icon.ico" Description="$(var.ProductName)" Target="[InstallFolder]$(var.MyApp.TargetFileName)" WorkingDirectory="InstallFolder"/>
<RemoveFolder Id="PROGRAMMENUFOLDER" On="uninstall"/>
<RegistryValue Root="HKCU" Key="Software\MyCo\MyApp" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
<Shortcut Id="UninstallProduct" Name="Uninstall $(var.ProductName)" Target="[SystemFolder]msiexec.exe" Arguments="/x [ProductCode]" Description="Uninstalls $(var.ProductName)" />
</Component>
</ComponentGroup>
I have removed the UninstallProduct element on my next version. Now when I install the first version, do a major upgrade to second version, then uninstall the shortcut remains. How do I ensure it's removed on major upgrade (even before uninstall). Major upgrade is scheduled afterInstallExecute (which must remain the case).
<MajorUpgrade Schedule="afterInstallExecute"/>
Fixed by removing shortcut using RemoveFile element:
<ComponentGroup Id="ProgramMenuComponents" Directory="PROGRAMMENUFOLDER">
<Component Id="ApplicationShortcut">
<Shortcut Id="ApplicationStartMenuShortcut" Name="$(var.ProductName)" Icon="icon.ico" Description="$(var.ProductName)" Target="[INSTALLFOLDER]$(var.MyApp.TargetFileName)" WorkingDirectory="INSTALLFOLDER"/>
<RemoveFile Id="RemoveOldUninstallShortcut" On="both" Name="[My shortcut file name].lnk" />
</Component>

wix - shortcut icon for website

I'm new on wix. In need to create a shortcut to a local website.
It works fine and creates the shorcuts, but it doesn't show any icon on start menu and desktop... The website has favicon file and when I open the site I can see it perfectly - I just don't see it in the shortcut. I tried to google it but I didn't find a good answer for util:InternetShortcut..
My code is:
<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="ApplicationShortcutBBBApp" Guid="---">
<util:InternetShortcut Id="ApplicationStartMenuShortcutBBBApp"
Name="BBB"
Target="http://localhost/BBB"/>
<util:InternetShortcut Id="ApplicationDesktopShortcutBBBApp"
Name="BBB"
Directory="DesktopFolder"
Target="http://localhost/BBB"/>
<RegistryValue Root="HKCU" Key="Software\Microsoft\BBB" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</DirectoryRef>
There is an easier solution for that problem. Instead of using InternetShortcut, you can just use the normal Shortcut and use a trick to set the target being a url.
<SetProperty Id="URL" Value="http://yourpage.com" Sequence="execute" Before="CreateShortcuts" />
<Shortcut Directory="DesktopFolder" Id="WebShortcut" Name="Your Page" Description="Your Page Description" Target="[URL]" Icon="IconDesktop">
<Icon Id="IconDesktop" SourceFile="images\icon.ico" />
</Shortcut>
"SetProperty" can be placed somewhere in your Product tag.
"Shortcut" should be placed instead of "InternetShortcut".
It is important to have the property [URL] as a Target. As a Property it can be an url. Diretctly written it doese not work.
There might be warnings in heat/candle/light, they can be ignored.
InternetShortcut doesn't support specifying an icon like a normal Shortcut. There's an open feature request for that. Technically, IUniformResourceLocator shortcuts in Windows don't support icons, though IShellLink shortcuts do.
A little late answering this, but just needed to do the same thing. The approach I took was to use the iniFile element to write out a url file.
Two points of interest with this approach:
Since the shortcut is on the desktop and the icon file is located elsewhere on the file system, I needed to create separate components to deploy the icon file.
If the MSI is ran as a normal user with UAC turned on, the icon is not set for the shortcut. Once I disabled UAC prior to installing, the icon was set correctly.
<Fragment>
<DirectoryRef Id="DesktopFolder">
<Component Id="ProductInternetShortcut" Guid="{YOUR_GUID_HERE}" >
<IniFile Id="url_name"
Action="addLine"
Directory="DesktopFolder"
Section="InternetShortcut"
Name="ProductInternetShortcut.url"
Key="URL"
Value="https://my.url.com/" />
<IniFile Id="url_target"
Action="addLine"
Directory="DesktopFolder"
Section="InternetShortcut"
Name="ProductInternetShortcut.url"
Key="Target"
Value="https://my.url.com/" />
<IniFile Id="url_idlist"
Action="createLine"
Directory="DesktopFolder"
Section="InternetShortcut"
Name="ProductInternetShortcut.url"
Key="IDList"
Value=" " />
<IniFile Id="url_HotKey"
Action="addLine"
Directory="DesktopFolder"
Section="InternetShortcut"
Name="ProductInternetShortcut.url"
Key="HotKey"
Value="0" />
<IniFile Id="url_icon"
Action="addLine"
Directory="DesktopFolder"
Section="InternetShortcut"
Name="ProductInternetShortcut.url"
Key="IconFile"
Value="PATH_TO_ICON_FILE_ON_WORKSTATION" />
<IniFile Id="url_iconIndex"
Action="addLine"
Directory="DesktopFolder"
Section="InternetShortcut"
Name="ProductInternetShortcut.url"
Key="IconIndex"
Value="0" />
<RegistryValue Root="HKCU" Key="Software\COMPANY\PRODUCT" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
</DirectoryRef>
<DirectoryRef Id="ProductFolder">
<Component Id="ShortcutIcons" Guid="{YOUR_GUID_HERE}">
<File Id="filProductIcons" KeyPath="yes" Source="PATH_TO_ICON_FILE_ON_DEVELOPER_MACHINE" />
</Component>
</DirectoryRef>
</Fragment>
In Wix you can create an InternetShortcut with an icon via the InternetShortcut Element (Util Extension).
Below is an example from an app I'm working on of adding a link to a website with an icon via the <InternetShorcut> element and placing that link on both the Desktop and the Start Menu.
Note, you may have to put the "util" prefix in front of the element name like so although I didn't have to do that: <util:InternetShortcut>.
<Directory Id="ProgramMenuFolder" Name="ProgramMenuFolder">
<Directory Id="ProgramMenuFolder.MyApplicationName" Name="MyApplicationName">
<Component Id="Component.Uninstall" Guid="215c7bec-7967-43e6-8f01-72c27fbb2a98">
<CreateFolder/>
<RemoveFolder Id="ProgramMenuFolder.MyApplicationName" On="uninstall"/>
<RegistryKey Root="HKCU" Key="Software\MyCompany\MyApplicationName">
<RegistryValue Value="0" Type="string" KeyPath="yes"/>
</RegistryKey>
</Component>
<Component Id="InternetShortcut" Guid="215c7bec-7967-43e6-8f01-72c22e505f09">
<InternetShortcut
IconFile="[INSTALLDIR]\icon.ico"
IconIndex="0"
Name="Admin Page"
Id="InternetShortcut"
Target="http://localhost:4444"
Type="link"
xmlns="http://schemas.microsoft.com/wix/UtilExtension"/>
<CreateFolder/>
<RegistryKey Root="HKCU" Key="Software\MyCompany\MyApplicationName">
<RegistryValue Value="0" Type="string" KeyPath="yes"/>
</RegistryKey>
</Component>
</Directory>
</Directory>
<Directory Id="DesktopFolder" Name="DesktopFolder">
<Component Id="InternetShortcut.1" Guid="B27DF351-6EDA-4BEF-A3AC-F12313260203">
<InternetShortcut
IconFile="[INSTALLDIR]\icon.ico"
IconIndex="0"
Name="Admin Page"
Id="InternetShortcut.1"
Target="http://localhost:4444"
Type="link"
xmlns="http://schemas.microsoft.com/wix/UtilExtension"/>
<CreateFolder/>
<RegistryKey Root="HKCU" Key="Software\MyCompany\MyApplicationName">
<RegistryValue Value="0" Type="string" KeyPath="yes"/>
</RegistryKey>
</Component>
</Directory>
<Feature Id="Complete" Title="Complete" Absent="allow" Level="1">
<ComponentRef Id="InternetShortcut"/>
<ComponentRef Id="InternetShortcut.1"/>
</Feature>
Also, see How To: Create a Shortcut to a Webpage

Run as admin the shortcut from startup

I created shortcut in the Startup folder. Is it possible to add "Run as administrator" property for my shortcut by wix? here my code:
<Component Id="AutostartService" Guid="GUID">
<Condition>AUTOSTART="1"</Condition>
<RegistryKey Action="createAndRemoveOnUninstall" Root="HKCU"
Key="Software\$(var.Manufacturer)\$(var.ProductName)\$(var.ApplicationName)">
<RegistryValue Name="ShortcutAutostart"
Type="integer" Value="1"
KeyPath="yes">
</RegistryValue>
</RegistryKey>
<Shortcut Advertise="no" Directory="StartupFolder"
Name="Service"
Target="[INSTALLLOCATION]Service.exe"
Id="SHORTCUT_auto"
WorkingDirectory="INSTALLLOCATION" >
</Shortcut>
<RemoveFile Id="remove_autostart" Name="Service" On="uninstall"/>
</Component>
No, it's not supported, because it's "the wrong thing to do."