On install I add a configuration key to a DB using a command line tool. On uninstall, I'm now trying to remove that configuration key. On an upgrade, I need to remove then add the configuration key back.
Here's my CustomAction "redacted" code:
<CustomAction Id="Unset_AppName_Version_Cmd"
Property="Unset_AppName_Version"
Execute="immediate"
Value=""[SystemFolder]cmd.exe" /C ""[SOMEDIR]SomeClTool" "uninstall:appname""" />
<CustomAction Id="Unset_AppName_Version"
BinaryKey="WixCA"
DllEntry="CAQuietExec"
Execute="immediate"
Return="check"
Impersonate="yes" />
Note: I've tried several values for execute, including oncePerProcess, firstSequence, and immediate.
Here's my InstallExecuteSequence "redacted" code:
<Custom Action="Unset_AppName_Version_Cmd" Sequence="1215">
(!AppName = 3 AND (&AppName = 3 OR &AppName = 2))
</Custom>
<Custom Action="Unset_AppName_Version" Sequence="1216">
(!AppName = 3 AND (&AppName = 3 OR &AppName = 2))
</Custom>
Note: Again, I tried to move around the sequence used. In the above example before InstallValidate, but also before RemoveFiles, RemoveODBC, etc.
Nothing has worked for me. In all instances, the
Executing op: ActionStart(Name=Unset_AppName_Version,,)
line is being run after RemoveFiles, so my custom action fails with:
CAQuietExec: The system cannot find the path specified.
CAQuietExec: Error 0x80070001: Command line returned an error.
CAQuietExec: Error 0x80070001: CAQuietExec Failed
After this, my installation gets rolled back.
Also, is this condition correct for run on uninstall or reinstall?
(!AppName = 3 AND (&AppName = 3 OR &AppName = 2))
Thanks
Update 7/31/2015
While I still do not have a working solution, I have made enough changes that it makes sense to post my current code.
Here's my updated CustomAction "redacted" code:
<CustomAction Id="Unset_AppName_Version_Cmd"
Property="QtExecCmdLine"
Value=""[SystemFolder]cmd.exe" /C ""[SOMEDIR]SomeClTool" "uninstall:appname"""
Execute="immediate" />
<CustomAction Id="Unset_AppName_Version"
BinaryKey="WixCA"
DllEntry="CAQuietExec"
Execute="immediate"
Return="ignore" />
Note: These changes were made based on Kiran's much appreciated suggestions and to mimic some taskkill commands that are working for me.
Example of working code:
<CustomAction Id="TaskKill_erl_exe_Cmd"
Property="QtExecCmdLine"
Value='"[SystemFolder]taskkill.exe" /F /IM erl.exe /T'
Execute="immediate" />
<CustomAction Id="TaskKill_erl_exe"
BinaryKey="WixCA"
DllEntry="CAQuietExec"
Execute="immediate"
Return="ignore"/>
Thanks
Couple of things here.
-You are trying to execute the custom action in immediate mode using the Wix provided inbuilt Quiet Execution Custom Action.
http://wixtoolset.org/documentation/manual/v3/customactions/qtexec.html
If you want to make use of CAQuietExec in immediate mode, the documentation clearly suggests that you have to set the WixQuietExecCmdLine property.
I dont see that being done in your case.
In your case, i see that you are setting a property named Unset_AppName_Version in the immediate mode. This just wont work.
-If you are trying to use CAQuietExec in deferred mode, your authoring of the custom actions in the pasted code snippet will work, as that would lead to populating the value of the inbuilt special property "CustomActionData"
-If the command line tool that you are trying to launch is installed by the msi package, then the custom action with Id="Unset_AppName_Version" has to be sequenced after "InstallFiles" standard action for the case of Install/Upgrade/Re-install.
For the case of uninstall, i am assuming you will have a seperate custom action which invokes this command line tool with a different set of parameters and it should be sequenced before "RemoveFiles" standard action.
-Finally, yes your condition is correct and will invoke the action on re-install or uninstall of the feature.
-Also when you run your msi package, if you want to confirm if the command line tool was indeed launched, you can have a utility named "ProcessMonitor" running. ProcessMonitor is from the Sysinternals suite. Keep the tool running by setting the appropriate filters.
If your tool is ever launched, ProcessMonitor will indicate the same to you.
Hope this helps.
This ended up working for me:
<CustomAction Id="Unset_AppName_Version_Cmd"
Property="QtExecCmdLine"
Value=""[SystemFolder]cmd.exe" /C ""[SOMEDIR]SomeClTool" "uninstall:appname"""
Execute="immediate" />
<CustomAction Id="Unset_AppName_Version"
BinaryKey="WixCA"
DllEntry="CAQuietExec"
Execute="immediate"
Return="ignore" />
And in the InstallExecuteSequence:
<Custom Action="Unset_AppName_Version_Cmd" Sequence="1215">
(!AppName = 3 AND (&AppName = 3 OR &AppName = 2))
</Custom>
<Custom Action="Unset_AppName_Version" Sequence="1216">
(!AppName = 3 AND (&AppName = 3 OR &AppName = 2))
</Custom>
The issue seems to be that something got messed up in my VM with all the rollbacks.
The main problem that I had was that I initially tried to name the property in the "Unset_AppName_Version_Cmd" CustomAction.
Thanks again to Kiran for all his help.
Related
I'm trying to create a MSI installer for my application which is a customized elasticsearch. I need to run elasticsearch-service.bat install command from cmd in the middle of installation. But whatever I do it will not execute successfully.
<CustomAction Id="InstallService" Directory="elasticsearch" Execute="deferred" Impersonate="no" ExeCommand='[SystemFolder] cmd.exe /c "bin\elasticsearch-service.bat install"' Return="check" />
<InstallExecuteSequence>
<Custom Action="InstallService" After="InstallFiles" />
</InstallExecuteSequence>
1721 and 1722 errors are vague and do not contain any additional information. What is the reason for these error? I was suspicious that these errors are due to lack of admin privileges. But I add InstallPrivileges=elevated and InstallScope=perMachine to package element and still getting the same error.
I agree with Stein, that you should use the built-in facilities of MSI/WiX to install the service, namely the <ServiceInstall> and <ServiceConfig> elements.
That being said, these are the errors of your current solution:
Space between [SystemFolder] and cmd.exe.
Executable path is not quoted.
Relative path to .bat file. Very fragile.
Possible solution:
<CustomAction Id="InstallService" Directory="elasticsearch" Execute="deferred" Impersonate="no" ExeCommand='"[elasticsearch]bin\elasticsearch-service.bat" install' Return="check" />
You can call a batch file directly, without passing it to cmd.exe.
This question seems to have been answered ad nauseam on this web site but I cannot get Wix to run an exe with Administrator rights (Windows 8.1 64-bit).
The installer I develop copies the prop.exe utility (http://prop.codeplex.com/) to a folder under Program Files (appfolder) as well as a file (my_file.propdesc) which needs to be registered/unregistered by prop.exe like:
prop schema register my_file.propdesc (at the end of installation)
prop schema unregister my_file (at the beginning of uninstallation)
These two command lines need to be run with Administrator privileges. Because these should also be run without a command prompt, I've used CAQuietExec with another CustomAction preparing the argument for CAQuietExec (prop.exe is 32-bit so it's CAQuietExec instead of CAQuietExec64 if I am not mistaken).
<CustomAction Id='PropReg_Prep' Property='PropReg' Value='"[appfolder]prop.exe" schema register "[appfolder]my_file.propdesc"' Execute='immediate' />
<CustomAction Id='PropUnReg_Prep' Property='PropUnReg' Value='"[appfolder]prop.exe" schema unregister "[appfolder]my_file.propdesc"' Execute='immediate' />
<CustomAction Id="PropReg" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="ignore" Impersonate="no" />
<CustomAction Id="PropUnReg" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="ignore" Impersonate="no" />
The custom actions are executed as per:
<InstallExecuteSequence>
<Custom Action="PropReg_Prep" After="CostFinalize" >NOT Installed</Custom>
<Custom Action="PropUnReg_Prep" After="CostFinalize" >Installed</Custom>
<Custom Action="PropUnReg" After="InstallInitialize" >Installed</Custom>
<Custom Action="PropReg" After="InstallFiles" >NOT Installed</Custom>
</InstallExecuteSequence>
I cannot get prop to register/unregister my_file.propdesc. Could someone help?
You are scheduling the actions as Execute='immediate' this runs as the user that executes the installer.
Switch to using Execute='deferred' this will run as the system account. Assuming that the prop.exe doesn't require a full profile to run this should work.
When you're not impersonating you're running with the system account, that's got admin privileges but if you are expecting it to be a user account then there might be issues.
The thing that looks weird to me is that [appfolder]prop.exe for a number of reasons. It doesn't look like a proper application folder, so make sure it's correct. It also needs to be in uppercase, making it a public property, and you should mark it Secure="yes" in the property element. The issue is that it may not get properly transferred from your immediate CA into the execute sequence where it's used.
p.s. Do the install creating a verbose log so you can see how those directory vales are actually being resolved at run time.
I am trying to execute the custom action at the time of uninstall the installer in wix.It is working perfectly but it is showing the splash screen of cmd prompt at the time of custom action.Latter I tried with CAQuietExec but it is unable to uininstall the installer and giving error.
(CAQuietExec: Error 0x80070057: failed to get command line data).
The command that I am using is :
<Fragment>
<Property Id="ModifyOutlookRegInitSign_14" Value=""[SystemFolder]reg.exe" ADD "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Security" /v InitSign /t REG_DWORD /d 0 /f"/>
<CustomAction Id="ModifyOutlookRegInitSign_14" BinaryKey="WixCA" DllEntry="CAQuietExec"
Execute="deferred" Return="check" />
<InstallExecuteSequence>
<Custom Action="ModifyOutlookRegInitSign_14" Before="InstallFinalize"></Custom>
</InstallExecuteSequence>
</Fragment>
If it is an immediate custom action, the name of the property containing the command line as value must have an Id="QtExecCmdLine". For other types of custom actions read Quiet Execution Custom Action.
It seems to me that you are trying to update HKCU during the uninstall. This is probably because Windows Installer doesn't natively support the ability to do so.
But your proposed solution is lacking in several way. Mainly that it doesn't support rollback and doesn't support cleaning up other user profiles.
Did this registry entry had to be implemented in HKCU? Could it be implemented in HKLM?
I've created a custom action to kill a process silently like this:
<!-- WixQuietExecCmdLine specify the cmd to be executed -->
<Property Id="WixQuietExecCmdLine" Value='"[WindowsFolder]System32\TaskKill.exe" /F /T /IM MyApp.exe'/>
<!-- From WiX v3.10, use WixQuietExec -->
<CustomAction Id="MyAppTaskKill" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="immediate" Return="ignore"/>
<!-- trigger the custom action -->
<InstallExecuteSequence>
<Custom Action='MyAppTaskKill' Before='InstallValidate'></Custom>
</InstallExecuteSequence>
You have more info about the possible configuration combinations here:
http://wixtoolset.org/documentation/manual/v3/customactions/qtexec.html
Wrap your custom action around a Property with Id set to WixQuietExecCmd.
<Property Id="WixQuietExecCmdLine" Value="command line to run"/>
WiX Property Element
WiX Quiet Execution of Custom Action
Here's my wix
<Binary Id="B.RenameFiles" SourceFile="RenameFiles.bat"/>
<CustomAction Id="CA.RenameFiles" BinaryKey="B.RenameFiles"
ExeCommand="RenameFiles.bat" Execute="immediate" Return='ignore'/>
<InstallExecuteSequence>
<Custom Action="CA.RenameFiles" Before="InstallValidate"></Custom>
</InstallExecuteSequence>
This doesn't work and spits out an error in the msi log "A program required for this install to complete could not be run". I'm not really sure if this is possible or if binary is only for use with exe's and dll's etc.
The way i'm doing it at the moment is to install the bat file and then run it from there but it would be neater if I could use it as a binary instead and not install it on the local machine.
Thanks
Neil
BAT files cannot be launched directly by Windows Installer custom actions. You need a custom action which uses ShellExecute to launch your BAT.
So you can't use a BAT as a Binary custom action.
Agree with Cosmin, you cannot execute BAT from binary, however you can launch it (almost) at any time during installation with help of "CMD.exe /C " custom action, and even have it run hidden (without cmd.exe window), i.e. for deffered CA one can use:
<CustomAction Id="Set_CA_HiddenBAT" Property="CA_HiddenBAT" Value=""cmd.exe" /c "[DirectoryWhereBatFileInstalled]Your.bat"" />
<CustomAction Id="CA_HiddenBAT" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="ignore" Impersonate="yes" />
Or if you want it visible:
<CustomAction Id="CA_LaunchBAT" Directory="DirectoryWhereToExecute" ExeCommand="CMD.exe /c "[DirectoryWhereBatFileInstalled]Your.bat"" Return="ignore" />
Note: Remember to run CA_HiddenBAT / CA_LaunchBAT after InstallFiles action and have added WixUtilExtension to your .wixproj:
<LinkerAdditionalOptions>-ext WixUtilExtension</LinkerAdditionalOptions>
<CompilerAdditionalOptions>-ext WixUtilExtension</CompilerAdditionalOptions>
There's also a way to launch BAT before InstallFile action, but this is tricky, let me know if you need this.
Ok I believe I'm following the online example in Wix3.5 for doing quiet commands yet I cannot seem to get my command to be executed quoted.
<Component Id="MapObjectsRuntime' Guid='*'>
<File Id = 'Mo23rtEXE' Name='Mo23rt.exe' Source='....' KeyPath="yes"/>
<Component>
<Property Id = "QtExecCmdLine" Value="Mo23rt.exe" />
// I've tried single & double quotes, and double double quotes around Mo23.
<CustomAction Id = "InstallMapObjects" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="immediate" Return="check" />
<InstallExecuteSequence>
<Custom Action="InstallMapObjects" After="InstallFinalize">NOT Installed</Custom>
</InstallExecuteSequence>
I do get a warning building the wix project:
The file Mo23rtEXE is not a Font, and its version is not a companion file reference.
I also need to assign command line parameters to the mo23rt.exe command but I'm first just trying to get this to work.
Lots of folks appear to be struggling with this too, as revealed by Google.
Forgot to add that running setup.exe /l*v install.log had:
MSI Doing action: InstallMapObjects
.
.
Property Change: Deleting QtExeCmdLine property. Its current value is 'Mo23rt.exe'.
CAQuitExec: Command string must begin with quoted application name.
CAQuietExec: Error 0x80070057 invalid command line property value
You schedule your custom action as immediate, but you try to run a file which should be installed by your installer. Here comes the conflict: immediate CA run BEFORE the files are installed, 'cause this happens in deferred sequence.
I would recommend you to get acquainted with Installation Phases and In-Script Execution Options for Custom Actions in Windows Installer article first.
I had tried ""mo23rt.exe"" and "'mo23rt.exe'", shame on me for not trying '"mo23rt.exe"'. Something else is still wrong but it might be what's mentioned above, or it might be I'm trying to run something that is trying to put up a status bar dialog and is not really that quiet.
I changed it to a regular custom action vice CAQuiet.
<CustomAction Id="InstallMapObjects" FileKey="Mo23rtEXE" ExeCommand="/ACDJKLM" Execute="commit"/>
followed by
<InstallExecuteSequence>
<Custom Action="InstallMapObjects" Before="InstallFinalize">NOT Installed</Custom>
</InstallExecuteSequence>