Admin Rights Prompt: In the WiX sample below, elevation will be requested and required for per-machine installation, but not for per-user installation.
Heads-Up: I personally do not like per-user setups. I find them to be borderline anti-patterns in my subjective opinion. It relates to poor serviceability (upgrades, patching, etc...) and a number of other details such as dubious folder redirects and some other "high-astonishment" factors. There are also a number of restrictions summarized nicely by the Advanced Installer guys: Advanced Installer: per-user setup limitations.
WiX Issue 5481: I added an answer, but deleted it. It didn't work properly. I had a look in the WiX Issues database and this is a known issue: https://github.com/wixtoolset/issues/issues/5481. The last comment from NicMay looked interesting. I made a quick mock-up below incorporating his / her suggestions with some modifications.
Disclaimer: The below sample has a number of defects, and is only intended as a "runnable sample"
. There are issues with MSI validation due to the shortcut quick-solution I used (use the shortcut to see where the file installed, right click and go "Properties"
). The "Create New Folder"
button in the custom installation dialog also has a bug. I will still post it to see if it helps you:
NB!: Create new WiX project, add reference to WixUIExtension.dll
, then follow comments. Run setup and click "Advanced"
to select per-user or per-machine install.
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<!--CHANGE #1: Add an UpgradeCode GUID below -->
<Product Id="*" Name="PerUserOrPerMachine" Language="1033" Version="1.0.0.0"
Manufacturer="Hobbit" UpgradeCode="PUT-GUID-HERE">
<Package InstallerVersion="200" Compressed="yes" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes" />
<Feature Id="ProductFeature" Title="PerUserOrPerMachine" Level="1" />
<!--CHANGE #2: Here we channel "hacker" NicMay with his / her dialog event tweaks mentioned in the WiX issue 5481 -->
<UI>
<UIRef Id="WixUI_Advanced" />
<Publish Dialog="InstallScopeDlg" Control="Next" Property="MSIINSTALLPERUSER" Value="1" Order="3">WixAppFolder = "WixPerUserFolder"</Publish>
<Publish Dialog="InstallScopeDlg" Control="Next" Property="MSIINSTALLPERUSER" Value="{}" Order="2">WixAppFolder = "WixPerMachineFolder"</Publish>
<Publish Dialog="InstallScopeDlg" Control="Next" Event="DoAction" Value="WixSetDefaultPerMachineFolder" Order="3">WixAppFolder = "WixPerMachineFolder"</Publish>
<Publish Dialog="InstallScopeDlg" Control="Next" Event="DoAction" Value="WixSetDefaultPerUserFolder" Order="3">WixAppFolder = "WixPerUserFolder"</Publish>
</UI>
<Property Id="ApplicationFolderName" Value="PerUserPerMachine" />
<Property Id="WixAppFolder" Value="WixPerMachineFolder" />
<!--CHANGE #3: Add components and files as appropriate -->
<Directory Id="TARGETDIR" Name="SourceDir">
<!--CHANGE #4: Make sure DesktopFolder is defined -->
<Directory Id="DesktopFolder" />
<Directory Id="ProgramFilesFolder">
<!--CHANGE #5: Crucial: Make sure Directory Id is APPLICATIONFOLDER (referenced elsewhere) -->
<Directory Id="APPLICATIONFOLDER" Name="PerUserOrPerMachine">
<Component Feature="ProductFeature" Guid="{5A74A1EE-0AD3-4C48-9E6B-4E4E3712A8BB}">
<!--CHANGE #6: Hard coded path below for simplicity, change path or replace construct -->
<File Source="D:\My Test Files\MyTestApplication.exe">
<Shortcut Id="AppDesktopShortcut" Name="PerUserOrPerMachine" Directory="DesktopFolder" />
</File>
<RegistryValue Root="HKCU" Key="Software\My Company\My Product" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
</Directory>
</Directory>
</Directory>
</Product>
</Wix>
Links:
- WiX Simple Setup Per User Installer (sample per-user setup - should not install directly to user profile folders, but set install to ProgramFiles and then allow MSI to do folder redirection).