25

We've gotten a custom action that runs command-line to work as such:

<CustomAction Id="OurAction" 
              FileKey="OurInstalledExe.exe"
              ExeCommand="our command line args" 
              Execute="deferred" 
              Return="check" />

The problem is, the user sees a console popup when the command runs.

The command line requires UAC elevation, but should not require any user interaction. We also install the file with the setup, the custom action runs After="InstallFiles".

How do we prevent the user from seeing the console?

Cheeso
  • 189,189
  • 101
  • 473
  • 713
jonathanpeppers
  • 26,115
  • 21
  • 99
  • 182

4 Answers4

7

Note that if you do require UAC elevation, then you need to ensure that it's a deferred execution CA. Here's the example from the manual with command line arguments added.

<CustomAction Id="QtExecDeferredExampleWithProperty_Cmd" Property="QtExecDeferredExampleWithProperty"
              Value="&quot;[#MyExecutable.exe]&quot; /arguments" Execute="immediate"/>
<CustomAction Id="QtExecDeferredExampleWithProperty" BinaryKey="WixCA" DllEntry="CAQuietExec"
              Execute="deferred" Return="check" Impersonate="no"/>
.
.
.
<InstallExecuteSequence>
    <Custom Action="QtExecDeferredExampleWithProperty_Cmd" After="CostFinalize"/>
    <Custom Action="QtExecDeferredExampleWithProperty" After="TheActionYouWantItAfter"/>
</InstallExecuteSequence>
saschabeaumont
  • 22,080
  • 4
  • 63
  • 85
  • 2
    This solution risks destroying your registry. I am compiling my installers from the command line, and the 'DllEntry="CAQuietExec"' line put my registry in an irreparable state due to the installer installing fine, but not having the files required on the way out. I spent hours trying to fix this before finally recreating my VM. I should have had restore points, but of course I didn't (my VM's base settings were questionable). This wasted hours of my time before I finally gave up. Be careful! – Shadoninja Oct 06 '15 at 18:04
2

If you have the source code of the EXE file this is what you can do. Make the EXE project Win32 Application project instead of Console Application.

If you cannot modify the source code of the EXE file, you can do this by:

  1. Creating a CustomAction DLL
  2. Calling a CustomAction in DLL (from WiX) to execute the process, by hiding the console window.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SysAdmin
  • 5,455
  • 8
  • 33
  • 34
  • We have no access to the source code of the process, we'd have written a custom action otherwise. Is this the only way? This seems like a no-brainer setting that WiX should have. Why should I have to write a custom action to start a process? – jonathanpeppers Mar 03 '10 at 17:22
1

There is a bit of a chicken and egg problem in that an executable has to be marked as a console app before it starts, and if you want to launch such an exe without the console popping up, it has to have its process created with the right flags. If your installer can't provide these, it is possible to use a third .exe in between. For example, the Keybase installer launches this small utility, called keybaserq.exe, in order to run persistent console apps in the background with no flashing black windows. It is open source and you can see how the Keybase installer makes use of it - no flashing console windows.

Steve
  • 169
  • 6
0

You just have to add second command "exit" for cmd.exe

ExeCommand="[SystemFolder]cmd.exe /C start MyExe.exe &amp; exit"

Hope, It helps you

Anton Sivov
  • 404
  • 6
  • 16
  • You would still see the console popup real quick. This is very undesirable, seems like poor UI design, and very "chop shop". – jonathanpeppers Jul 04 '12 at 23:54
  • 1
    Wix has this issue since 2007th year. The issue has not still fixed. Using cmd is working workaround for me in little programs. I used don't use Wix. – Anton Sivov Jul 05 '12 at 10:55
  • 3
    Because Acceptance answer doesn't work for me, but my solution id Ok for me. Title of your question is "WiX - CustomAction ExeCommand - Hide Console". I spent too much time before I solved my problem. Why do you think I answer for you only? There are too many other guys, who need help. I did not create new branch, so I answered here. – Anton Sivov Jul 12 '12 at 08:58