JARRRRG
JARRRRG

Reputation: 926

WiX Installer InstallPrivileges="elevated" not working

When I run my installer I get the following issue.

error

I'm doing some custom actions which require to access the registry and I can only think that its because the WiX configuration doesn't make it request admin priveleges. I've looked at some posts on SO and tried to use.

InstallPrivileges="elevated" 

within the package element however this does not make the installer have the admin shield nor request it therefore still producing the error.

Extra information about test project.

The name of my application is :WindowsFormsApplication33, the name of the custom action project is CustomAction1 and name of the Setup project is SetupProject1.

This is my current wix xml file.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="TestProject Installer" Language="1033" Version="1.0.0.0" Manufacturer="Jagga" UpgradeCode="3f4613a9-b0c5-4775-8df7-3bbe3221aa88" >

    <Package InstallerVersion="200" Compressed="yes" InstallPrivileges="elevated" InstallScope="perUser" />

<Binary Id="CustomAction1.CA.dll" SourceFile ="..\CustomAction1\bin\$(var.Configuration)\CustomAction1.CA.dll" />
<CustomAction Id="disableTaskManager"
              Return="check"
              Execute="immediate"
              BinaryKey="CustomAction1.CA.dll"
              DllEntry="disableTaskManager" />

<CustomAction Id="enableTaskManager"
              Return="check"
              Execute="immediate"
              BinaryKey="CustomAction1.CA.dll"
              DllEntry="enableTaskManager" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

    <MediaTemplate />

    <Feature Id="ProductFeature" Title="SetupProject1" Level="1">
        <ComponentGroupRef Id="ProductComponents" />
    </Feature>


<InstallExecuteSequence>
  <Custom Action="disableTaskManager" Before="InstallFinalize"  />
  <Custom Action="enableTaskManager" After="InstallInitialize"><![CDATA[(NOT UPGRADINGPRODUCTCODE)]]></Custom>
</InstallExecuteSequence>

</Product>

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="Form Test Application" />
        </Directory>
    </Directory>
</Fragment>

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
  <Component Guid="{EDA315F6-A115-4348-8607-981C252EA317}">
  <File Source="$(var.WindowsFormsApplication33.TargetPath)" KeyPath ="yes" />
  </Component>
  <Component Guid="{E3182F61-F563-4C13-82B5-8CC39D9DB380}">
    <File Source="$(var.CustomAction1.TargetPath)" KeyPath ="yes" />
  </Component>
  <Component Guid="{E4AF325E-B244-47F5-855A-5B40DBC425D2}">
    <File Source="..\WindowsFormsApplication33\bin\Release\WindowsFormsApplication33.exe.config" KeyPath="yes" />
  </Component>
    </ComponentGroup>
</Fragment>
</Wix>

Update: changing the InstallScope value from perUser to "perMachine" does make a UAC prompt however the DLL error still exists..

Upvotes: 2

Views: 4097

Answers (4)

ShadowlessGT
ShadowlessGT

Reputation: 41

If you use MajorUpgrade Element, which is a good practice as it removes older versions before installing the new version. This means that when installing, it should uninstall the older version before installing the new version.

But if you use Upgrade Item and the MajorUpgrade element can interfere with each other when used together. Since the MajorUpgrade element is basically a simplified and improved version of the Upgrade element, I recommend that you remove the Upgrade element and only use the MajorUpgrade element.

I used it like this:

<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

Upvotes: 0

PhilDW
PhilDW

Reputation: 20780

Your custom action is immediate, that means it will not run with elevation. It must be deferred to run with elevation. It's got nothing to do with WiX particularly, it's just that immediate custom actions run as the user but limited.

Upvotes: 4

123r789
123r789

Reputation: 1790

Use these three attributes inside custom action tag.

<CustomAction ....
Execute="deferred" 
Impersonate="no" 
Return="ignore" />

These fields will make the custom action to run with admin priveleges.

Upvotes: 1

JARRRRG
JARRRRG

Reputation: 926

I struggled to get rid of the dll error however an alternative I found was to NOT use Custom Action and use the XML in the wix file to create the registry and then delete the key when uninstalling via the use of :

ForceDeleteOnUninstall="yes"

You have to use this in the

Example :

<!-- Register windows autostart registry -->
   <Component Id="RegistryEntries" Guid="45C7AC46-1101-4301-83E1-D24392283A60">
      <RegistryValue Type="string"
               Name="FooStartup"
               Value="[#FooMainApp]"
               Root="HKLM"
               Key="Software\Microsoft\Windows\CurrentVersion\Run"
               Action="write"/>
   </Component>

As found on : Registry change upon installing application C#

I really hope this helps someone new to WiX as it did to me.

Upvotes: 1

Related Questions