Home > other >  Install exe file silently using CMD and PowerShell
Install exe file silently using CMD and PowerShell

Time:11-25

I am trying to install an exe created using inno script. When I try to install it using PowerShell with

 Start-Process -wait C:\updatefile.exe /VERYSILENT

all folders are created at proper places, registry values are created, but console hangs and does not reuturn unless Ctrl C is pressed.

But if I install exe using Command Prompt with

start /wait C:\updatefile.exe /VERYSILENT

everything goes properly and command prompt returns.

What could be cause of this anomaly?

I need this exe to install through Dockerfile, but as powershell install is hanging, container does not install exe. Even with CMD version in dockerfile, container does not create install folders.

///// After checking logs I found that exe service is being started by installer in end, if that is reason for hanging, can by some argument I can come out of powershell

CodePudding user response:

The -Wait switch of PowerShell's Start-Process cmdlet also waits for child processes of the launched process to exit[1], whereas cmd.exe's internal start command does not.

  • As you note in a later comment, a service executable is launched by your installer at the end; given that services run indefinitely, Start-Process also waiting for that (child) process to terminate indeed explains the hang.

Here is a simple workaround:

cmd /c C:\updatefile.exe /VERYSILENT

When an executable is called via cmd /c, cmd.exe implicitly waits until the executable's process - and only it - terminates, even if it is a GUI application, just like start /wait would.


Given the behavior described in footnote [1], another workaround is to use the -PassThru switch with Start-Process (instead of -Wait) and pipe the result to Wait-Process:

Start-Process -PassThru C:\updatefile.exe /VERYSILENT | Wait-Process

[1] See GitHub issue #15555, which also discusses that Wait-Process acts differently in that only waits for the process itself to terminate.
As zett42 points out, the behavior of Start-Process -Wait is now at least briefly mentioned in the docs as well (emphasis added): "waits for the specified process and its descendants".

CodePudding user response:

try

$arguments = "/Verysilent" Start-Process -wait C:\updatefile.exe -ArgumentList $arguments

  • Related