Set environment variable before running user action on WiX

I need to create the MSI installer using WiX , and I need to set the MY_HOME environment before running the command action.

I have a component:

 <Component Id="SEMYHOME" Guid="*my guid*"> <CreateFolder /> <Environment Id="MY_HOME" Action="set" Part="all" Name="MY_HOME" Permanent="no" System="yes" Value="[APPLICATIONPATH]myapp"/> </Component> 

Then I have a custom action:

 <CustomAction Id="InstallMyService" Directory="INSTALLDIR" ExeCommand='&quot;[INSTALLDIR]myapp\install_service.bat&quot; install' Execute="immediate" Return="ignore"/> <InstallExecuteSequence> <Custom Action="InstallMyService" After="InstallFinalize"/> </InstallExecuteSequence> 

NOTE. This action requires the MY_HOME variable, which must be set before starting.

When installing this MSI, I received a log showing that before running the custom "InstallMyService" action, a command was set before the MY_HOME parameter, but the command to install my service was still not running. I found that the reason for calling the MY_HOME command has not yet been established.

After the installation was completed, MY_HOME was installed as expected, but the user action failed: (

How can I fix this problem?

+4
source share
2 answers

Windows Installer and user actions are hosted through the Service Control Manager, which has a long history of non-compliance with broadcast messages sent with environment change announcements. Therefore, even if you fix the immideiate / delay problem that Yang is talking about, you will find that your user action still does not have an environment variable.

Why not just pass "[APPLICATIONPATH] myapp" to your .bat file and get it as% 2?

By the way, I also do not recommend calling batch files from the installer. It is fragile and embarrassing to see installations that trigger the appearance of small black windows.

+6
source

You ca immediately. This means that it starts immediately when the Windows installer processes your MSI package. And this, obviously, happens before the component containing <Environment/> is installed. Modify it to defer ( Execute="deferred" ) and schedule until InstallFinalize.

+2
source

Source: https://habr.com/ru/post/1333128/


All Articles