Wix: Add shortcut not in a subfolder! - wix

I want to add a shortcut in my program menu. i tried:
<Component Id='myId' Guid='E4DED108-0129-4a5b-83FE-C9D1E3025B00'>
<File Id='MyFileID' Name='Prog.exe' DiskId='1' Source='.\Prog.exe' KeyPath='yes'>
<Shortcut Id='myShortcut' Name='Prog' Icon='MyIcon.exe' IconIndex='0' Directory='ProgramMenuDir' Advertise='yes' />
</File>
</Component>
but the installer add the shortcut in a subfolder in the program menu! Why and what can i do to avoid this?
Thanks Micha

You can try to change Directory='ProgramMenuDir' into Directory='ProgramMenuFolder', otherwise make a seperate shortcuts component;
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramMenuFolder">
<Component Id="Shortcuts" Guid="{}">
<Shortcut Id='myShortcut' Name='Prog' Icon='MyIcon.exe' IconIndex='0' Directory='ProgramMenuFolder' WorkingDirectory='INSTALLDIR' Target="[INSTALLDIR]Prog.exe" />
<RegistryValue Root='HKCU' Key='SOFTWARE\prog\prog' Type='string' Value='1' KeyPath='yes' />
</Component>
</Directory>
<!-- other files -->
</Directory>

Related

WiX tool - unable to add a desktop shortcut

I have created an installer of a c# application. Now I want to add a Desktop shortcut: I have followed the WiX official documentation as well as the other suggested answers on this site but still my installer doesn't create the shortcut.
No errors occur during the compilation. My .wsx file is the following:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="APPLICATIONROOTDIRECTORY" Name="Myapp">
<Component Id="Trojan2CostCalculator.exe" Guid="*">
<File Id="Myapp.exe" Source="$(var.Myapp.TargetPath)" KeyPath="yes" Checksum="yes"/>
</Component>
<Directory Id="DesktopFolder" Name="Desktop">
<Component Id="ApplicationShortcutDesktop" Guid="*">
<Shortcut Id="ApplicationDesktopShortcut"
Name="Myapp"
Description="Made by me"
Target="$(var.Myapp.TargetPath)Myapp.exe"
WorkingDirectory="APPLICATIONROOTDIRECTORY" />
<RemoveFolder Id="DesktopFolder" On="uninstall"/>
<RegistryValue
Root="HKCU"
Key="Software\Myapp"
Name="installed"
Type="integer"
Value="1"
KeyPath="yes" />
</Component>
</Directory>
...
and I have added the component:
<Feature Id="MainApplication" Title="Main Application" Level="1">
<ComponentRef Id="ApplicationShortcutDesktop"/>
</Feature>
The installation succesfully completes but no shortcut is created. What am I missing?
I think your Shortcut's 'Target' is wrong. You're passing it the build time source path. It should be something like "[APPLICATIONROOTDIRECTORY]Myapp.exe". See - wixtoolset.org/documentation/manual/v3/xsd/wix/shortcut.html

Shortcut using WIX

I have an installer that creates a folder "_source" in the targetdir, which contains the "SAMPLE.exe" and other files. I am trying to generate a shortcut that will point to that exe but it seems to generate/copy that exe and place it in the target directory. Its able to run the executable but since other files are needed in the _source directory, it cannot continue. How do I point to the exe in _source without making a copy of that exe?
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="DesktopFolder" SourceName="Desktop"/>
<Directory Id="MergeRedirectFolder">
<Component Id="ApplicationShortcut" Guid="1D120AC7-6BAC-4F99-8611-029ED3F2EA3A">
<File Id="MyExeFile" Source="!(wix._source)\SAMPLE.exe" KeyPath="yes">
<Shortcut Id="DesktopShortcut" Directory="DesktopFolder" Name="SAMPLE" WorkingDirectory="MergeRedirectFolder"
Icon="SAMPLE.exe"
IconIndex="0"
Advertise="yes" >
<Icon Id="SAMPLE.exe" SourceFile="!(wix._source)\icon1.ico" />
</Shortcut>
</File>
</Component>
</Directory>
If you are attempting to install under program files, i would start with something like this:
<Product ...>
...
<Feature ...>
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<Icon Id="SAMPLE.ico" SourceFile="!(wix._source)\icon1.ico" />
</Product>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="MergeRedirectFolder" />
</Directory>
<Directory Id="DesktopFolder" SourceName="Desktop"/>
</Directory>
<ComponentGroup Id="ProductComponents" Directory="MergeRedirectFolder">
<Component Id="ApplicationShortcut" Guid="1D120AC7-6BAC-4F99-8611-029ED3F2EA3A">
<File Id="MyExeFile" Source="!(wix._source)\SAMPLE.exe" KeyPath="yes">
<Shortcut Id="DesktopShortcut" Directory="DesktopFolder" Name="SAMPLE" WorkingDirectory="MergeRedirectFolder"
Icon="SAMPLE.ico"
IconIndex="0"
Advertise="yes" />
</File>
</Component>
</ComponentGroup>

create msi using wix

I am developing a wix code to create a msi. i have added all the components and libraries to my wix project.But,i am not able to create a msi as i need.Please help me out.Here is my code,
<?xml version='1.0' encoding='UTF-8'?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Name='SmartViewer'
Id="*"
Language='1033'
Codepage='1252'
Version='1.0.0'
UpgradeCode='9C5E4073-EFDE-419B-935D-CE2632BC560E'>
<Package Keywords='Installer,MSI'
InstallerVersion='100'
Languages='1031'
Compressed='yes'
SummaryCodepage='1252' />
<Media Id="1" Cabinet="myapp.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="MyProgramDir" Name="myproject" >
<Directory Id="INSTALLFOLDER" Name="proj1" />
</Directory>
</Directory>
<DirectoryRef Id="INSTALLFOLDER">
<Component Id='MainExecutable' Guid='*'>
<File Id='ExecutableFile' Name='mv.exe' DiskId='1' Source='mv.exe' KeyPath='yes'/>
</Component>
<Directory Id="imageformats" Name="imageformats">
<Component Id='jpeg4Library' Guid='*'>
<File Id='jpeg4' Name='jpeg4.dll' DiskId='1' Source='jpeg4.dll' KeyPath='yes' />
</Component>
</Directory>
<Component Id='Network4Library' Guid='*'>
<File Id='Network4' Name='Network4.dll' DiskId='1' Source='Network4.dll' KeyPath='yes' />
</Component>
<Component Id='Multimedia4Library' Guid='*'>
<File Id='Multimedia4' Name='Multimedia4.dll' DiskId='1' Source='Multimedia4.dll' KeyPath='yes' />
</Component>
<Component Id='QtGui4Library' Guid='*'>
<File Id='Gui4' Name='Gui4.dll' DiskId='1' Source='Gui4.dll' KeyPath='yes' />
</Component>
<Component Id='Designer4Library' Guid='*'>
<File Id='Designer4' Name='Designer4.dll' DiskId='1' Source='Designer4.dll' KeyPath='yes' />
</Component>
<Component Id='Core4Library' Guid='*'>
<File Id='Core4' Name='Core4.dll' DiskId='1' Source='Core4.dll' KeyPath='yes' />
</Component>
<Component Id='libmfxsw32Library' Guid='*'>
<File Id='libmfxsw32' Name='libmfxsw32.dll' DiskId='1' Source='libmfxsw32.dll' KeyPath='yes' />
</Component>
<Component Id='libiomp5mdLibrary' Guid='*'>
<File Id='libiomp5md' Name='libiomp5md.dll' DiskId='1' Source='libiomp5md.dll' KeyPath='yes' />
</Component>
<Component Id='ippcore7.1Library' Guid='*'>
<File Id='ippcore7.1' Name='ippcore-7.1.dll' DiskId='1' Source='ippcore-7.1.dll' KeyPath='yes' />
</Component>
<Component Id='ippccw77.1Library' Guid='*'>
<File Id='ippccw77.1' Name='ippccw7-7.1.dll' DiskId='1' Source='ippccw7-7.1.dll' KeyPath='yes' />
</Component>
<Component Id='ippccv87.1Library' Guid='*'>
<File Id='ippccv87.1' Name='ippccv8-7.1.dll' DiskId='1' Source='ippccv8-7.1.dll' KeyPath='yes' />
</Component>
<Component Id='ippccs87.1Library' Guid='*'>
<File Id='ippccs87.1' Name='ippccs8-7.1.dll' DiskId='1' Source='ippccs8-7.1.dll' KeyPath='yes' />
</Component>
<Component Id='ippccp87.1Library' Guid='*'>
<File Id='ippccp87.1' Name='ippccp8-7.1.dll' DiskId='1' Source='ippccp8-7.1.dll' KeyPath='yes' />
</Component>
<Component Id='ippccg97.1Library' Guid='*'>
<File Id='ippccg97.1' Name='ippccg9-7.1.dll' DiskId='1' Source='ippccg9-7.1.dll' KeyPath='yes' />
</Component>
<Component Id='ippcc7.1Library' Guid='*'>
<File Id='ippcc7.1' Name='ippcc-7.1.dll' DiskId='1' Source='ippcc-7.1.dll' KeyPath='yes' />
</Component>
<Component Id='EULALibrary' Guid='*'>
<File Id='EULA' Name='EULA.rtf' DiskId='1' Source='EULA.rtf' KeyPath='yes' />
</Component>
</DirectoryRef>
<Directory Id="ProgramFilesFolder">
<Directory Id="MyProgramDir" Name="myproj" >
<Directory Id="INSTALLFOLDER" Name="proj1" /
<Component Id="TextFileComponent" Guid="*">
<File Id="TextFile" Name="Logs.txt" DiskId="1"
Source="Logs.txt" KeyPath="yes" />
</Component>
</Directory>
</Directory>
<Directory Id="DesktopFolder">
<Component Id="ExecutableFileShortcutComponent" Guid="*">
<Shortcut Id="ExecutableFileShortcut" Name="smart viewer"
Description="Shortcut To Executable File"
Target="[INSTALLFOLDER]mv.exe" />
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="MyProgramDir" Name="myproj">
<Component Id="ExecutableFileShortcutComponent" Guid="*">
<Shortcut Id="ExecutableFileShortcut" Name="smart viewer"
Description="Shortcut To Executable File"
Target="[INSTALLFOLDER]mv.exe" />
</Component>
</Directory>
</Product>
</Wix>
The components are not getting the dll path.I tried passing the path to source in file id,still i find the same issue.Looking forward for a good suggestion.
You need to reference the full path to the files:
<File Id="Microsoft.Practices.Unity"
Name="jpeg4.dll"
Source="$(var.BuildOutputDir)\jpeg4.dll" />
where $(var.BuildOutputDir) is the full path to a folder. If these files are in the output of another referenced project then you can use $(var.OtherProject.TargetDir)
Your file does not contain valid XML. The following fragment is broken.
<Directory Id="ProgramFilesFolder">
<Directory Id="MyProgramDir" Name="myproj" >
<Directory Id="INSTALLFOLDER" Name="proj1" /
<Component Id="TextFileComponent" Guid="*">
<File Id="TextFile" Name="Logs.txt" DiskId="1"
Source="Logs.txt" KeyPath="yes" />
</Component>
</Directory>
</Directory>
The line
<Directory Id="INSTALLFOLDER" Name="proj1" /
should be
<Directory Id="INSTALLFOLDER" Name="proj1" >
There is one </Directory> missing. You should also add </Component> at two positions. Try WiXEdit that points to invalid XML when it loads a .WXS file.
Additionally you should add a <feature>.

Create shortcut to desktop using WiX

How do I create a shortcut on the desktop from a wix setup project?
The shortcut is a non-advertised one.
Remember to put the component in your feature tag.
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="DesktopFolder" Name="Desktop">
<Component Id="ApplicationShortcutDesktop" Guid="*">
<Shortcut Id="ApplicationDesktopShortcut"
Name="Text under your icon"
Description="Comment field in your shortcut"
Target="[MYAPPDIRPROPERTY]MyApp.exe"
WorkingDirectory="MYAPPDIRPROPERTY"/>
<RemoveFolder Id="DesktopFolder" On="uninstall"/>
<RegistryValue
Root="HKCU"
Key="Software\MyCompany\MyApplicationName"
Name="installed"
Type="integer"
Value="1"
KeyPath="yes"/>
</Component>
</Directory>
<Directory Id="ProgramFilesFolder" Name="PFiles">
<Directory Id="MyCompany" Name="MyCompany">
<Directory Id="MYAPPDIRPROPERTY" Name="MyAppName">
<!-- main installation files -->
</Directory>
</Directory>
</Directory>
</Directory>
I think my way is easier, no need for you to create a registry key:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="DesktopFolder" SourceName="Desktop" />
<Directory Id="MergeRedirectFolder">
<Component Id="MyExeComponent" Guid="{PUT-GUID-HERE}">
<File Id="MyExeFile" Source="$(var.ExeSourcePath)" KeyPath="yes">
<Shortcut
Id="DesktopShortcut"
Directory="DesktopFolder"
Name="$(var.ShortcutName)"
WorkingDirectory="MergeRedirectFolder" />
</File>
</Component>
</Directory>
</Directory>
Thanks for example. In WIX 3.8 it still raises:
"Error 3 ICE43: Component ... has non-advertised shortcuts. It should use a registry key under HKCU as its KeyPath, not a file."
So I did this such way in a file with features:
<Component Id="cmp79F6D61F01DD1060F418A05609A6DA70"
Directory="dirBin" Guid="*">
<File Id="fil34B100315EFE9D878B5C2227CD1454E1" KeyPath="yes"
Source="$(var.SourceDir)\FARMS.exe" >
<Shortcut Id="DesktopShortcut"
Directory="DesktopFolder"
Name="FARMS $(var.FarmsVersion)"
Description="Local Land Services desktop application"
WorkingDirectory="INSTALLFOLDER"
Icon="FARMS.exe"
IconIndex="0"
Advertise="yes" >
<Icon Id="FARMS.exe" SourceFile="$(var.SourceDir)\FARMS.exe" />
</Shortcut>
</File>
</Component>
And mentioned desktop folder in a file with product definition:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="DesktopFolder" Name="Desktop" />
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="FARMS" >
</Directory>
</Directory>
</Directory>
</Fragment>
It seems lot easier in this documentation.
First, you have to point your DesktopFolder,
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="DesktopFolder" Name="Desktop"/>
Then you should create Shortcut component for file that you want to create shortcut of.
<Component Id="PutYourComponentIdHere" Directory="FileDirectory" Guid="*">
<File Id="NotYourComponentId" KeyPath="yes" Source="..\YourFileSource\YourExecutable.exe">
<Shortcut Id="desktopServer" Directory="DesktopFolder" Name="YourShourtcutName" WorkingDirectory='WhereShouldYourShortcutPoint' Advertise="yes"/>
</File>
</Component>
It worked for me. I need to put icon but thats easy part. Hope it works.
After too much effort, I used this way:
<Product ...>
<Feature Id="ProductFeature" Title="SetupProject" Level="1">
...
...
<ComponentRef Id="cmpDesktopShortcut" />
</Feature>
<Component Id="cmpDesktopShortcut" Guid="PUT-GUID-HERE" Directory="DesktopFolder" >
<Shortcut Id="MyDesktopShortcut"
Name="Setup Project"
Description="Opens the program."
Directory="DesktopFolder"
Target="[INSTALLFOLDER]App.exe"
WorkingDirectory="INSTALLFOLDER"/>
<RegistryValue Root="HKCU" Key="Software\My Company\Sample Application" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
</Product>
I believe that using a "Current User" (HKCU) registry key as Key Path causes problems on a multi-user machine tool. Because the registry key is only created for the current user and when a different user logs in, then the auto-repair of the installation kicks in.

Folder within Program Menu Folder for WiX 3

Following some example code on the net, I got my first WiX installer to work. However, it placed my program menu shortcut directly on Program Menus. I really want to create a folder, Sample, in Program Menus for my link.
Original Code:
<Shortcut Id="startmenuSample" Directory="ProgramMenuFolder" Name="Sample 0.5"
WorkingDirectory='INSTALLDIR' Icon="Sample.exe" IconIndex="0" Advertise="yes">
Attempt at modifying code (fails with compiler error):
<Shortcut Id="startmenuSample" Directory="ProgramMenuFolder\Sample" Name="Sample 0.5"
WorkingDirectory='INSTALLDIR' Icon="Sample.exe" IconIndex="0" Advertise="yes">
Note the addition of \Sample.
How do I go about adding that link to a new folder in the Program Menu?
This is a sample test I did, when I was asked to do the same thing
<Package InstallerVersion="200" Compressed="yes" />
<WixVariable Id="Manufacturer" Value="StackOverFlowHelper"/>
<WixVariable Id="ShortProduct" Value="ShortCuts"/>
<Media Id="1" Cabinet="WixShortCut.cab" EmbedCab="yes" />
<Icon Id="ShortCutIcon" SourceFile="YOUR.ico"/>
<!-- The icon that appears in Add & Remove Programs. -->
<Property Id="ARPPRODUCTICON" Value="ShortCutIcon" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="ManufacturerFolder" Name="!(wix.Manufacturer)">
<Directory Id="INSTALLLOCATION" Name="!(wix.ShortProduct)">
<Component Id="ProductComponent" Guid="{YOUR_GUID}" KeyPath="yes">
<CreateFolder/>
</Component>
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ProgramMenuManufacturer" Name="!(wix.ShortProduct)" />
</Directory>
</Directory>
</Directory>
<DirectoryRef Id="ProgramFilesFolder">
<Component Id="ProgramMenuShortcuts" Guid="{YOUR_GUID}">
<CreateFolder Directory="ProgramMenuManufacturer"/>
<RemoveFolder Id="RemoveMenuShortcuts" Directory="ProgramMenuManufacturer" On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\!(wix.Manufacturer)\!(wix.ShortProduct)" Name="InstalledStartMenuShortcuts" Type="integer" Value="1" />
</Component>
</DirectoryRef>
<DirectoryRef Id="INSTALLLOCATION" FileSource="Files">
<Component Id="WixShortCut" Guid="{YOUR_GUID}">
<File Id="Test.ShortCut" Vital="yes" Name="A_DOC.pdf" />
<CreateFolder />
<RegistryKey Root="HKCU" Key="Software\!(wix.Manufacturer)\!(wix.ShortProduct)" Action="createAndRemoveOnUninstall">
<RegistryValue Name="ShortCut" Value="1" Type="integer" KeyPath="yes"/>
</RegistryKey>
<!-- Shortcut in Start menu. -->
<Shortcut Id="ProgramMenuApplicationShortcut" Name="!(wix.ShortProduct)" Target="[#Test.ShortCut]"
Directory="ProgramMenuManufacturer" Show="normal" Icon="ShortCutIcon"/>
</Component>
</DirectoryRef>
<Feature Id="ProductFeature" Title="WixShortCuts" Level="1">
<ComponentRef Id="ProductComponent"/>
<ComponentRef Id="ProgramMenuShortcuts"/>
<ComponentRef Id="WixShortCut"/>
</Feature>
In Windows Installer you need to create a new directory under ProgramMenuFolder and then reference it.
<Directory Id="ProgramMenuFolder" >
<Directory Id="ProgramMenuDir" Name='My Folder'>
</Directory>
</Directory>
<Shortcut Id="startmenuSample" Directory="ProgramMenuFolder" Name="Sample 0.5"
WorkingDirectory='INSTALLDIR' Icon="Sample.exe" IconIndex="0" Advertise="yes">