MSI Installer: Help running a UI based EXE with a CustomAction from a service based installer - wix

I have created a MSI installer package using Wix Toolset 3.8 that is run by a third party installer service running under the "SYSTEM" account. My issue is that when trying to launch and run an installed executable from my MSI installer using a custom action, it also runs under the SYSTEM account instead of the administrator account that is currently logged in. I have spent hours researching on the net and from what I have read, specifying Impersonate="yes" will run that particular custom action under the account that launched the installer, but there lies the issue. Since the third party installer service is running from the SYSTEM account, specifying Impersonate="yes" would just run the custom action under the SYSTEM account as well correct? At least that's what my tests have shown. A little bit of background on my MSI installer:
InstallScope="perMachine"
<CustomAction Id="StartAction"
Directory="FOLDER"
ExeCommand ='cmd.exe /c start MYEXE.exe /tray'
Execute="immediate"
Impersonate="yes"
Return="check"/>
<InstallExecuteSequence>
<Custom Action='StartAction' Before='InstallFinalize'>NOT Installed</Custom>
</InstallExecuteSequence>
I have tried both "deferred" and "immediate" for Execute as well as setting "Impersonate" to both yes and no. Is there any way to make this work? I thought about using the runas command but I wouldn't know the password of the user account that initiated the install.
Thanks!

What is the EXE file doing? Do you have control of the application so you can move the logic from that external EXE into the main application's launching logic?
Other than that you can register such an EXE file to run once per user via ActiveSetup. You can also find another answer from me here.
Here is one more link to an explanation of ActiveSetup (I prefer the one above): http://www.ewall.org/tech/msi/self-healing
Also see these answer here: Stopping MSI from launching an EXE in the SYSTEM context

Related

Run .exe inside Wix msi with admin rights

I am running the .exe file through a CustomAction in Wix. The executable is running but not with admin rights. Seems like i am doing everything correct but not sure what's going wrong. Here is the sample of my Custom Action
<CustomAction Id="RunExe" FileKey="Setup" ExeCommand="-switch" Execute="deferred" Return="check" Impersonate="no"/>
<InstallExecuteSequence>
<Custom Action="RunExe" Before="InstallFinalize">NOT Installed</Custom>
</InstallExecuteSequence>
The actual problem is that this .exe that is executed through ExeCommand is not able to access a registry key(HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders).
Running the msi as administrator solve the problem but i need a solution in which WIX should itself able to run the command as admin or atleast give a prompt to user.
A deferred custom action in a per machine install runs elevated with the system account. It's not clear what you mean by access to the HKCU key, but the HKCU key for an executable running with the system account is the system account's HKCU, not the installing user's HKCU. It would help if you said exactly what you are trying to achieve, because you might not need code at all. The install will update HKCU for the installing user if you use the registry features of WiX/MSI, so this may be a case of not really needing code at all.
It's also unclear why running the MSI as administrator solves the problem because that custom action will already be elevated in a per machine install with InstallPrivileges elevated. There is insufficient info in your post as tp your install context, but my guess is that you might be doing a per user install without InstallPrivileges elevated - that's one situation in which the MSI would run CAs under the installing user's account but they would not be elevated unless you elevate the entire install by doing as you said - runningthe MSI as administrator.

WiX CustomAction fails to start program with "Application cannot be restarted - Application SID does not match Conductor SID" warning

I have a client application for tracking user status ("Gone for the day", "Out to lunch", etc.) that needs to be started as part of its installation process. I have set up a wix installer to handle the installation and in particular a CustomAction to launch the application once the installation is complete. Below is the xml
<CustomAction Id="Launch_StatusTracker" FileKey="StatusTracker" ExeCommand=""
Return="asyncNoWait" />
<InstallExecuteSequence>
<Custom Action="Launch_StatusTracker" After="InstallFinalize">NOT Installed</Custom>
<Custom Action="WixCloseApplications" Before="InstallInitialize">Installed</Custom>
</InstallExecuteSequence>
The code above executes just fine when I manually run the generated msi on my machine. It installs the application and then starts it up. However, when the application is installed using an SCCM 2012 Application the program is installed but it does not startup. Here is the warning message that I see in the Windows Event Viewer:
Application 'C:\Program Files\StatusTracker\StatusTracker.exe' (pid 7216) cannot be restarted - Application
SID does not match Conductor SID.
I've looked online for this type of error but I haven't been able to find anything about it that relates to SCCM. As an alternative I tried to have it run a batch file instead that will startup the program but that will not work for me because I need the program to run in the context of the current user.
What context is SCCM running the installer in? Typically it's SYSTEM and that's probably causing problems trying to start the process in the interactive user context. I used to have some tricks to get around this but they are all hacks. You may just have to take a reboot and have it start on next logon.
You can use PSEXEC to launch a command prompt as SYSTEM. Test the install silent in that context to mimic SCCM behavior.

Wix installer: The application is launched in SYSTEM user

I have an installer in WIX. I have tried to deploy it to a group of target computers in the network and encountered the following issue. The deployment was successful but there is an issue when the installer launches the application after the installation finishes using the following code:
<CustomAction Id="RunMainApp" Directory="SUBDIR" ExeCommand="[SUBDIR]clicksharelauncher.exe" Execute="deferred" Return="asyncNoWait"/>
<InstallExecuteSequence>
<Custom Action="RunMainApp" Before="InstallFinalize"><![CDATA[UILevel=5 OR LAUNCH_APP~="YES" AND NOT Installed]]></Custom>
</InstallExecuteSequence>
When the application is launched, I realized that it is launched in SYSTEM user. Therefore, I get an error from the application saying that the application can't run in SYSTEM user. Could anyone tell me if there is a way to fix it?
This is happening because the InstallExecute phase of the installation runs as the SYSTEM account, and you're launching the application during that phase.
You'll need to get the custom action to Impersonate the user executing the installation by adding Impersonate="yes" to the custom action element.
More details can be found under the Impersonate section here:
http://wixtoolset.org/documentation/manual/v3/xsd/wix/customaction.html
The following link provides details on how to add the startup of an application in the UI:
http://wixtoolset.org/documentation/manual/v3/howtos/ui_and_localization/run_program_after_install.html

Install program fails to shutdown running target...workarounds?

I have a WIX install program.
When I test my install program on a machine where the old version of the software is running, I get the prompt below.
The problem is that the installer can't manage to close the application. When the new program runs, it complains about the old one running.
Is there a way to forcefully kill the app?
If not, is there some entry in WIX that will require the user to shutdown the application before it will continue installation?
I found the answer here:
WiX <util:CloseApplication> element not working
I made one tweak to the solution in the post above. I kill the application earlier in the install sequence so the window above doesn't appear.
<!-- Code to force termination of running program...MSIExec couldn't do it -->
<Property Id="QtExecCmdLine" Value='"[WindowsFolder]\System32\taskkill.exe" /F /IM "$(var.ProductName).exe"'/>
<CustomAction Id="APP.TaskClose" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="immediate" Return="ignore"/>
<InstallExecuteSequence>
<Custom Action="APP.TaskClose" After="LaunchConditions"/>
</InstallExecuteSequence>
If you are wondering what "$(var.ProductName).exe" is, I pass the exe name on the commandline because I'm creating several branded versions of the same program. Just substitute your exe name.
And yes, it is safe in this particular intance to do this. There is no data held in memory that could be lost.
You should use the WiX util extension CloseApplication:
http://wixtoolset.org/documentation/manual/v3/xsd/util/closeapplication.html
That should work.
Long term you should get the app integrated with Restart Manager so it will shut down automatically.

WIX MSI customaction not running when deployed using Group Policy

I'm using WIX to create an MSI which has a custom action to install a clickonce application. I want to deploy the MSI via GPO. The custom action runs fine when I just double click to run the msi, but the custom action does not seems to be running when deployed via GPO. But if you look at the add/remove programs in the control panel you have the product/msi listed there as if it was successfully installed.
To see if custom actions work at all when deploying via GPO I created a simple custom action which just writes a file to c:\temp (existing) folder. Added the custom action to both InstallExecuteSequence and AdminExecuteSequence in before installfinalize step. Tried both deffered execute and immediate execute. It works when you double click the msi to install but not via GPO.
Is it possible to have custom actions when the msi is deployed through GPO? Are there any limitations? Is there anything special that I need to do to get it to work with GPO?
Thanks in advance!
Rukshan
I figured it out. The issue was that I hadn't configured the GPO to install the package when the user logs in. After checking that check box in the group policy properties it works.
If you assign the software to users and do not check "install this application at logon", the application will be listed on the user's add/remove programs panel but doesn't really install it. So I was under the impression that it was successfully installed without running the custom action when it really wasn't installed.
Now I have my custom action listed under Install Execute sequence
<InstallExecuteSequence>
<Custom Before='InstallFinalize' Action='ClickOnceIntallCustomAction' >NOT REMOVE</Custom>
</InstallExecuteSequence>
And it is set to execute immediately and check on return
<CustomAction Id="ClickOnceIntallCustomAction" BinaryKey="ClickOnceInstallBinary" Return="check" Execute="immediate" DllEntry="Test" ></CustomAction>