4

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.

Cedt
  • 251
  • 1
  • 14
  • Look up [MSIINSTALLPERUSER](https://msdn.microsoft.com/en-us/library/windows/desktop/dd408007) and the rest of [Single Package Authoring](https://msdn.microsoft.com/en-us/library/windows/desktop/dd408068). (Sorry I don't have the time to flesh this out into an answer right now.) – Michael Urman Aug 02 '17 at 12:36
  • Michael, thanks for your feeback. I've been digging into it, and it seems nice, however I couldn't make the Single Package Authoring indications into a solution. I'll edit my original post accordingly to explain what I did. – Cedt Aug 02 '17 at 14:44
  • 1
    These are also preprocessor directives and are set at compile time, not runtime. there should be some well-defined mechanism for doing this since several installers I've used in the past have the "per-user or all user" radio button selection in them. – Brian Sutherland Aug 02 '17 at 14:58
  • Brian, you are right. Unfortunately I need Wix to detect on its own wether the installation should be per machine or user, and I cannot use any radio buttons in my UI. – Cedt Aug 02 '17 at 15:09
  • As Brian says, your approach is trying to use a build-time conditional for a run-time condition. (AdminUser is a run-time property.) Instead of `` you need to use [SetProperty](http://wixtoolset.org/documentation/manual/v3/xsd/wix/setproperty.html) actions (or control events if you ever put it in the UI) sequenced with a condition that references, e.g., AdminUser. – Michael Urman Aug 03 '17 at 12:24
  • Did you ever figure this out? – rfcdejong Dec 13 '17 at 15:47
  • Unfortunately, I didn't. I have never been able to set the property during the installation. See my edit for details. – Cedt Dec 14 '17 at 15:54

0 Answers0