File tree 2 files changed +18
-2
lines changed
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,15 @@ function Install-FromExe {
46
46
Write-Information - MessageData (' Installing {0} ...' -f $name ) - InformationAction Continue ;
47
47
Write-Information - MessageData (' {0} {1}' -f $installerPath , ($options -join ' ' )) - InformationAction Continue ;
48
48
49
- Start-Process $installerPath - Wait - ArgumentList $options ;
49
+ # According to https://stackoverflow.com/a/23797762 caching the handle is required to get ExitCode
50
+ $process = Start-Process $installerPath - PassThru - ArgumentList $options ;
51
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSUserDeclaredVarsMoreThanAssignments' , ' ' , Scope= ' Function' )]
52
+ $handle = $process.Handle ;
53
+ $process.WaitForExit ();
54
+
55
+ if ($process.ExitCode -ne 0 ) {
56
+ Write-Error (' {0} installer failed with exit code {1}' -f $name , $process.ExitCode ) - ErrorAction Stop;
57
+ }
50
58
51
59
# Update path
52
60
Update-ScriptPath ;
Original file line number Diff line number Diff line change @@ -49,7 +49,15 @@ function Install-FromMsi {
49
49
Write-Information - MessageData (' Installing {0} ...' -f $name ) - InformationAction Continue ;
50
50
Write-Information - MessageData (' msiexec {0}' -f ($msiArgs -join ' ' )) - InformationAction Continue ;
51
51
52
- Start-Process msiexec - Wait - ArgumentList $msiArgs ;
52
+ # According to https://stackoverflow.com/a/23797762 caching the handle is required to get ExitCode
53
+ $process = Start-Process msiexec - PassThru - ArgumentList $msiArgs ;
54
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSUserDeclaredVarsMoreThanAssignments' , ' ' , Scope= ' Function' )]
55
+ $handle = $process.Handle ;
56
+ $process.WaitForExit ();
57
+
58
+ if ($process.ExitCode -ne 0 ) {
59
+ Write-Error (' {0} installer failed with exit code {1}' -f $name , $process.ExitCode ) - ErrorAction Stop;
60
+ }
53
61
54
62
# Update path
55
63
Update-ScriptPath ;
You can’t perform that action at this time.
0 commit comments