I have Inno Setup installer that run in very silent mode (it's working).
But when I'm running my Inno Setup installer through PowerShell script with admin rights – I get endless execution. Also, the following script code (SetEnvironmentVariable
) is not executed even after successful installation.
$installerArguments = $requiredInstallerArguments + $additionalInstallerArguments
Start-Process -FilePath $installerFile.FullName -ArgumentList $installerArguments -Wait
[Environment]::SetEnvironmentVariable('WebPort', (GetValueByKey -array $additionalInstallerArguments -key "/webport"), [EnvironmentVariableTarget]::Machine)
Why does this happen and how to fix it?
Sometimes I have to use the .WaitForExit()
method
$Process = Start-Process -FilePath $installerFile.FullName -ArgumentList $installerArguments -PassThru
$Process.WaitForExit()
Start-Process
... -Wait
behaves differently than (Start-Process ... -PassThru).WaitForExit()
/ Start-Process
... -PassThru | Wait-Process
: the former waits for the entire child process tree to terminate, whereas the latter return once the immediate child process has terminated (see GitHub issue #15555). Thus, if an installer spawns a child process that keeps running after the installer has exited, -Wait
won't return until that child process terminates.
In SysInternals Process Monitor, you can use Tools->Process Tree to see these process trees.