How to call a command line program in WiX
Asked Answered
B

3

7

I want to call a command line program of OpenOffice in WiX. To do so, I created a custom action, as seen below:

<CustomAction Id="ca_RunOpenOfficeProgram" Return="check" Directory="TARGETDIR"  ExeCommand="cmd.exe /K &quot;C:\OpenOffice.org3\program\unopgk.com list --shared&quot;" />

The Custom Action is being run in an Install Execute Sequence:

<InstallExecuteSequence>            
  <Custom Action="ca_RunOpenOfficeProgram" Before="InstallFinalize" />
 </InstallExecuteSequence>

When running the resulting MSI-File, I receive the following error message in a command line:

Invalid command 'C:\OpenOffice.org3\program\unopkg.com' could not be found.

Well, of course, the command is available and I may run it from command line. But it just doesnt work if the command line is being called by WiX. It`s also notable that the part 'list --shared' is completely ignored.

Does anyone know what`s going on here?

Birdlime answered 10/7, 2013 at 9:41 Comment(0)
B
0

Found the solution for my problem:

1) As written in my answer to Toms post, I had in typo in the command line ... stupid.

2) The quotes regarding the command line call had been misplaced (Toms answer)

3) I found out that running 'unopkg.com' with the 'shared' parameter is only executed when the command line is being run with administration rights. I thought that the attribute 'impersonated="yes"' in my CustomAction would be enough, but it didn`t help. Guess I have to dig deeper into documentation of WiX regarding UAC.

Also thanks to Ralf. I didnt try his solutions, but you might give it a shot.

Birdlime answered 12/7, 2013 at 7:19 Comment(0)
K
5

I would recommend using the ShellExecute custom action from the WiX toolset.

Here is the sample code:

<Property Id="WixShellExecTarget" Value="[#myapplication.exe]" />
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />

Change the Value of property WixShellExecTarget to cmd.exe /K &quot;C:\OpenOffice.org3\program\unopgk.com list --shared&quot; and it should work.

Kigali answered 10/7, 2013 at 11:58 Comment(0)
K
4

Are you sure that cmd.exe /K "C:\OpenOffice.org3\program\unopgk.com list --shared" works? It looks like you have the quotes in the wrong place.

And, do you really want the console window kept open (/k)? Does the user have to enter more commands before the installation continues? You might want /c instead. See the help with cmd /?.

But, if there is only one command needed, why not just run the program directly?

ExeCommand="&quot;C:\OpenOffice.org3\program\unopgk.com&quot; list --shared"

Finally, if the above is the only command needed and assuming C:\OpenOffice.org3\program\unopgk.com is a console application, a useless console window will be opened. This can be avoided with WiX's QtExecCmdLine custom action.


If you are running the program to gather information, and it is a console application, you could do:

cmd /c &quot;C:\OpenOffice.org3\program\unopgk.com&quot; list --shared >path\out.txt

and use another custom action to read the file and make decisions on it or show it to the user in a Windows Installer dialog. This would be a better experience than leaving the user with a console window with a blinking prompt that they have to exit out of.

Keilakeily answered 10/7, 2013 at 14:18 Comment(2)
Had I typo, the program is called 'unopkg.com'. Corrected it, my CustomAction looks like this now: <CustomAction Id="ca_RunOpenOfficeProgram" Return="check" Directory="TARGETDIR" Execute="deferred" ExeCommand="&quot;C:\OpenOffice.org3\program\unopkg.com&quot; list --shared" Impersonate="yes" /> When running the MSI, I receive the following error message: 'There is ap roblem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personal [...]'Birdlime
Check the log file. The return value (exit code) of the program might be important. To run msiexec with logging see here.Keilakeily
B
0

Found the solution for my problem:

1) As written in my answer to Toms post, I had in typo in the command line ... stupid.

2) The quotes regarding the command line call had been misplaced (Toms answer)

3) I found out that running 'unopkg.com' with the 'shared' parameter is only executed when the command line is being run with administration rights. I thought that the attribute 'impersonated="yes"' in my CustomAction would be enough, but it didn`t help. Guess I have to dig deeper into documentation of WiX regarding UAC.

Also thanks to Ralf. I didnt try his solutions, but you might give it a shot.

Birdlime answered 12/7, 2013 at 7:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.