Exit Codes
The CLI reports its outcome through a numeric exit code (available as %ERRORLEVEL% in batch scripts or $LASTEXITCODE in PowerShell). Scripts should always check the exit code to determine whether an operation succeeded.
Exit Code Reference
| Code | Name | Meaning | Typical Causes |
|---|---|---|---|
| 0 | Success | Operation completed successfully | Export/import finished without errors; help displayed (--help); compliance report generated; preflight passed (with or without warnings) |
| 1 | User Error | Invalid arguments or missing required parameters | Unrecognized parameter (e.g. --foo); parameter not allowed in active mode (e.g. --mappingFile with export); missing --manifestFile or --apps; file path not ending in .xml; invalid date format for --reportFrom/--reportTo; --unc-user combined with --unc-credential-store; --userSettingsFile not found or failed XSD validation |
| 2 | System Error | Runtime failure during the operation | Not running as administrator; another instance already running; export/import I/O failure; UNC connection failed; manifest file not found (import); restore point creation failed (without --ignoreRestorePointLimit); preflight failed with errors |
| 3 | License Error | License validation failed | License file missing; license expired beyond grace period; signature invalid; environment binding mismatch (domain or tenant). See License Troubleshooting. Note: in preflight mode, license errors are reported within the preflight report (exit code 2) rather than as a standalone code 3. |
| 4 | SIEM Error | SIEM is configured and active but unreachable | TCP connection to the SIEM host/port failed; DNS resolution failed; TLS handshake failed. The CLI refuses to operate when SIEM is enabled but cannot be reached. Disable SIEM in siem.xml or fix connectivity. |
| 5 | Audit Error | Audit log integrity check failed | Defined as a constant but not currently used as an exit code. Audit integrity failures are treated as warnings — the CLI logs the violation, sends a SIEM event (if active), and continues the operation. No operation is aborted due to an audit integrity failure. See Audit Logging. |
Error Output
When a validation error occurs (exit code 1), the CLI writes the specific error message followed by the full help text to stderr. In --silentMode, neither the error message nor the help text is written to the console — check the application log for details.
The --help flag writes to stdout (not stderr) and always exits with code 0.
Using Exit Codes in Scripts
Batch script:
AppProfileSafe.exe --export --manifestFile "C:\Backup\Manifest.xml" --apps "Firefox" --silentMode
IF %ERRORLEVEL% NEQ 0 (
echo Export failed with code %ERRORLEVEL%
exit /b %ERRORLEVEL%
)
PowerShell:
& "AppProfileSafe.exe" --export --manifestFile "C:\Backup\Manifest.xml" --apps "Firefox" --silentMode
if ($LASTEXITCODE -ne 0) {
Write-Error "Export failed with code $LASTEXITCODE"
exit $LASTEXITCODE
}
PowerShell with granular handling:
& "AppProfileSafe.exe" --export --manifestFile "C:\Backup\Manifest.xml" --apps "Firefox" --silentMode
switch ($LASTEXITCODE) {
0 { Write-Host "Export completed successfully." }
1 { Write-Error "Invalid arguments. Check command syntax." }
2 { Write-Error "System error. Check the application log." }
3 { Write-Error "License error. Verify your license file." }
4 { Write-Error "SIEM unreachable. Check network or disable SIEM." }
default { Write-Error "Unexpected exit code: $LASTEXITCODE" }
}
Preflight Exit Codes
When running with --preflight, the exit code reflects the preflight result:
- 0 — All checks passed, or passed with warnings only. Warnings are included in the JSON report and console summary but do not cause a non-zero exit.
- 2 — One or more checks reported errors. The JSON report contains the full error details.
Preflight bypasses the main license gate but performs its own internal license check. An invalid license appears as an error in the preflight report (exit code 2), not as a standalone exit code 3.
The full preflight report is saved as a JSON file in the report folder. If the report file cannot be written (e.g. permissions), a warning is printed but the preflight result is still reported on the console and via exit code.