I'm using Wix 3.11 and trying to set the install privileges of my package conditionally.
What I'm trying to do is:
<?if Privileged = 0 ?>
<Package InstallerVersion="405" Compressed="yes" InstallScope="perUser" InstallPrivileges="limited" />
<?else ?>
<Package InstallerVersion="405" Compressed="yes" InstallScope="perMachine" InstallPrivileges="elevated" />
<?endif ?>
However this doesn't work. When installing, the one with elevated privileges is always picked.
Also, I've tried to create a variable in a .wxi file and set it like this:
.wxi file:
<?if Privileged = 0 ?>
<?define myScope = "perUser" ?>
<?define myPrivileges = "limited" ?>
<?else?>
<?define myScope = "perMachine" ?>
<?define myPrivileges = "elevated" ?>
<?endif?>
.wxs file:
<Package InstallerVersion="405" Compressed="yes" InstallScope="$(var.myScope)" InstallPrivileges="$(var.myPrivileges)" />
But the same happens again: elevated privileges are always picked.
I did my tests on 2 different machines, with non-admin users.
I did not find any solution on the internet so I'm wondering: is it possible to set up a package conditionally?
Thanks for your time.
EDIT:
I have found the AdminUser property, which seems to be exactly what I need. I changed my wxs file accordingly to have AdminUser set:
<Package InstallerVersion="500" Compressed="yes" />
<SetProperty Id="MSIUSEREALADMINDETECTION" Value="1" Sequence="first"/>
<SetProperty Id="ALLUSERS" Value="2" Sequence="first"/>
<SetProperty Id="MSIINSTALLPERUSER" Value="1" Sequence="first"> <![CDATA[NOT AdminUser]]> </SetProperty>
When reading the log file of the installation, I noticed AdminUser was set before MSIUSEREALADMINDETECTION, and setting MSIUSEREALADMINDETECTION wouldn't trigger a reset for AdminUser.
I scheduled my SetProperties to the most prior action I could find, which was "FindRelatedProducts", however AdminUser is set even before that (actually before both installExecuteSequence and installUISequence), I was unable to get MSIUSEREALADMINDETECTION set first.
I believe there is no way to determine wether you are running your installation under an admin or a standard session.
If anyone know a solution, please feel free to advise.
Thank you Michael and Brian for your time.