How can I get the return code from a CustomAction?

核能气质少年 提交于 2019-12-10 03:26:43

问题


I have the following CustomAction in my project:

<CustomAction Id="InstallDriver"
                  Return="check"
                  Execute="deferred"
                  Impersonate="no"
                  FileKey="FileDriverInst"
                  ExeCommand="-install" />

<InstallExecuteSequence>
    <Custom Action="InstallDriver" Before="InstallServices" />
</InstallExecuteSequence>

The program that installs the driver produces useful return codes, for example if the installation failed because the system needs to be restarted following a previous driver uninstall.

Currently if anything other than success is returned, I get a dialog saying 'A program run as part of the setup did not finish as expected.' and the installation fails. This is not optimal.

How can I get and handle return codes?


回答1:


Windows Installer doesn't support handling custom action return values.

For an EXE custom action a non-zero return value is interpreted as an error and the installation stops. Only a win32 DLL or VBScript custom action can change the installation behavior through its return code, but it's still very limited.

If you want to reboot the machine after install, you can set the REBOOT property.




回答2:


Added as an "answer" by request:

Your whole design is not optimal. It's out of process to Windows Installer and isn't declarative. There are better patterns for installing drivers.

That's simply the way MSI handles EXE calls. You'd have to write your own custom actions to wrap the EXE call and then interpret the failure reason. To me this just adds yet another failure point.




回答3:


You can't get a return code from a CustomAction, but in a round about way you can set what that return code would be on a property. That might as well be the same thing as getting the return code.

You have to get it within the script/dll your custom action is performing. Otherwise, the return code only shows up in the log.

For example, if you have property like

<Property="MyCode" Secure="yes">

Then within VBScript (or Jscript) you can get the value of that property like this:

VBScript

Session.Property("MyCode")

Initially, it is null. You can set it in VBScript like this:

If someCondition = 4 Then
  Session.Property("MyCode") = "4" // For a return code of 4
End If

Once back in your WiX .wxs file, if you look at the value of your property, it is now 4. You could even use it in CDATA tags.

For example, only spawn a dialog if MyCode is equal to 4.

<Publish Dialog="SpawnDialog" ...><![CDATA[ MyCode = 4 ]]></Publish>


来源:https://stackoverflow.com/questions/10229434/how-can-i-get-the-return-code-from-a-customaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!