Skip to content

$cs.Shell_Execute

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.

$cs.Shell_Execute(string command, string arguments = “”, bool wait = true, int windowstyle = 0, bool mustexist = false, string workingdirectory = “”)

Command to execute.

Arguments for the command. Default is empty.

Wait for the command to complete before returning. Default is $true. If $false, the process is started asynchronously and 0 is returned immediately.

Window style for the command: 0=hidden, 1=normal, 2=minimized, 3=maximized. Default is 0 (hidden).

Check that command exists before executing; returns 5 without running anything if it doesn’t. Default is $false.

Working directory for the command. Default is empty.

Integer. The process’s exit code if wait=$true, or 0 immediately if wait=$false.

Terminal window
$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:

Terminal window
$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:

Terminal window
$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
}

$cs.Shell_ExecuteWithTimeout