$cs.Shell_Execute
Description
Section titled “Description”Executes a command with optional arguments and returns its exit code. Use this instead of Start-Process for running installers and other external commands from a PowerPack — it’s the standard way to run an MSI/EXE and capture its result.
Syntax
Section titled “Syntax”$cs.Shell_Execute(string command, string arguments = “”, bool wait = true, int windowstyle = 0, bool mustexist = false, string workingdirectory = “”)
Parameters
Section titled “Parameters”command (String)
Section titled “command (String)”Command to execute.
arguments (String)
Section titled “arguments (String)”Arguments for the command. Default is empty.
wait (Boolean)
Section titled “wait (Boolean)”Wait for the command to complete before returning. Default is $true. If $false, the process is started asynchronously and 0 is returned immediately.
windowstyle (Int32)
Section titled “windowstyle (Int32)”Window style for the command: 0=hidden, 1=normal, 2=minimized, 3=maximized. Default is 0 (hidden).
mustexist (Boolean)
Section titled “mustexist (Boolean)”Check that command exists before executing; returns 5 without running anything if it doesn’t. Default is $false.
workingdirectory (String)
Section titled “workingdirectory (String)”Working directory for the command. Default is empty.
Return value
Section titled “Return value”Integer. The process’s exit code if wait=$true, or 0 immediately if wait=$false.
Example
Section titled “Example”$cs.Shell_Execute("msiexec.exe", "/i `"$Packageroot\kit\GoogleChromeStandaloneEnterprise64.Msi`" /QN REBOOT=REALLYSUPPRESS ALLUSERS=1")Install an MSI with the log written to $global:AppLogFolder, so it’s automatically uploaded and visible in the CapaInstaller Console:
$MsiPath = Join-Path $global:Packageroot "kit" "7zip.msi"$LogPath = Join-Path $global:AppLogFolder "7zip_Install.log"$Arguments = "/i `"$MsiPath`" /qn /norestart /log `"$LogPath`""
$Result = $cs.Shell_Execute("msiexec.exe", $Arguments)if ($Result -ne 0 -and $Result -ne 3010) { $cs.Job_WriteLog("7-Zip installation failed with exit code: $Result") Exit-PSScript $Result}Run an EXE from the kit folder with mustexist=$true so a missing installer fails fast with a clear exit code instead of a confusing native error, and a specific working directory:
$SetupExe = Join-Path $global:Packageroot "kit" "setup.exe"$Result = $cs.Shell_Execute($SetupExe, "/S /v/qn", $true, 0, $true, (Join-Path $global:Packageroot "kit"))if ($Result -eq 5) { Exit-PSScript -exitcode 1 -exitmessage "setup.exe was not found in the kit folder"} elseif ($Result -ne 0) { $cs.Job_WriteLog("Installation failed with exit code: $Result") Exit-PSScript $Result}