6

Possible Duplicate:
Wix - change the installation folder based on privilege

Well this question arised when I was trying to solve my problem in How do I get different registry keys for allusers and single user.

Basically what I'm trying to do is:

if ALLUSERS=1 then
   set InstallDir to Property1
else 
   set InstallDir to Property2

Anyone know to do this?

Community
  • 1
  • 1
Deqing
  • 14,098
  • 15
  • 84
  • 131
  • 2
    It looks like this question has been quite [thoroughly answered here](http://stackoverflow.com/questions/1017294/wix-change-the-installation-folder-based-on-privilege). – anton.burger Aug 14 '12 at 09:05

2 Answers2

6

Ok, just finished. My wxs looks like:

<CustomAction Id="PerUserInstall"    Property="InstallDir" Value="[INSTALLDIR1]" Execute="immediate" />
<CustomAction Id="PerMachineInstall" Property="InstallDir" Value="[INSTALLDIR2]" Execute="immediate" /> 
<InstallExecuteSequence>
    <Custom Action="PerUserInstall"    After="AppSearch">ALLUSERS="" OR (ALLUSERS=2 AND (NOT Privileged))</Custom>      
    <Custom Action="PerMachineInstall" After="AppSearch">ALLUSERS=1  OR (ALLUSERS=2 AND Privileged)</Custom>
</InstallExecuteSequence>

Thanks @shambulator for the link. Note that I use After="AppSearch" instead of Before="CostFinalize" because that will make action executing right after registry search.

Deqing
  • 14,098
  • 15
  • 84
  • 131
3

Many WiX elements take a condition as the inner text. Since it's XML you'll frequently need to escape special characters. Here's a pointer to how the conditions work:

Conditional Statement Syntax

Also, I'm not sure why you have INSTALLDIR1 and INSTALLDIR2. Without seeing the rest of your code I'd have to say you aren't going about it correctly. You should have one INSTALLDIR and then set it to different locations depending on per user or per machine. Here's a good blog article on the subject:

Authoring a single package for Per-User or Per-Machine Installation context in Windows 7

Personally, I rarely bother with per-user installations. They are a pain with little value other then 'viral' (not a virus, but spread through social media to non priv users ) applications.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100