WiX - CustomAction ExeCommand - Hide Console

社会主义新天地 提交于 2019-12-29 04:30:11

问题


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?


回答1:


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>



回答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.



回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/2372978/wix-customaction-execommand-hide-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!