Question

have been trying to create a WiX installer for my latest project. I have a strange issue where if I run the msi via cmd prompt as admin it works fine, the custom actions kick off without a fuss and everything works fine, but if I double click the msi the custom actions don't work and the installer fails. I'm using Visual Studio 2012 and using Windows 7.

<!--Custom Actions-->
<Binary Id='customShortcut' SourceFile='$(var.CustomDir)\TestInstallerCustom.CA.dll'/>
<Binary Id='customDir' SourceFile='$(var.CustomDir)\TestInstallerCustom.CA.dll'/>
<Binary Id='removeDir' SourceFile='$(var.CustomDir)\TestInstallerCustom.CA.dll'/>

<CustomAction Id='customShortcutId' BinaryKey='customShortcut' DllEntry='CustomShortcut'
              Execute='immediate' Impersonate='no' Return='check' />
<CustomAction Id='customDirId' BinaryKey='customDir' DllEntry='CustomDir'
              Execute='immediate' Impersonate='no' Return='check'/>
<CustomAction Id='removeDirId' BinaryKey='removeDir' DllEntry='RemoveDir'
              Execute='immediate' Impersonate='no' Return='check'/>

<InstallExecuteSequence>
  <Custom Action='customDirId' Before='InstallFinalize'/>
  <Custom Action='customShortcutId' After='InstallFinalize'/>
  <Custom Action="removeDirId" After="InstallValidate">REMOVE="ALL"</Custom>
</InstallExecuteSequence>
Était-ce utile?

La solution

The 'immediate' custom actions are not executed by the elevated part of the install. Thus they are only elevated in the installation process is run elevated (as you've seen). To have the custom action be elevated they must part of the transaction script. To do that set the CustomAction element Execute='deferred' attribute.

Note: Deferred custom actions have other limitations that are documented in the MSI SDK: 'Deferred Execution Custom Actions' topic. Since it looks like the custom actions are modifying machine state, you'll also want to look into adding rollback custom actions to undo the changes that are done by the deferred custom actions.

Writing custom actions well is quite challenging. That is part of the reason why custom actions are the largest contributor to installation failures. If you can avoid writing custom actions, I highly recommend doing so. :)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top