Operations, Scripts

Non-standard success exit codes

Some software distribution tools do not allow custom success exit codes. This means that if a software package returns a non-standard success exit code that the deployment status might return a failure instead of a success.

With this script an installation package's non-standard success exit codes can be translated to exit code 0 within the software distribution tool.

Example: CScript.exe Setup.vbs /Command:SomeSetup.exe /SuccessCodes:1;2;3
In this example exit code 1, 2 and 3 for SomeSetup.exe will be changed to 0

Download: Setup.zip

Option Explicit

On Error Resume Next

Dim strCommand
Dim strSuccessCodes

strCommand = WScript.Arguments.Named("Command")
strSuccessCodes = WScript.Arguments.Named("SuccessCodes")

If Len(Trim(strCommand)) = 0 Or Len(Trim(strSuccessCodes)) = 0 Then
    WScript.Quit(1)
End If

Dim arrSuccessCodes
Dim intSuccessCode

arrSuccessCodes = Split(strSuccessCodes, ";")

Dim objShell
Dim objExec
Dim intReturnCode

Set objShell = CreateObject("WScript.Shell")

Err.Clear
Set objExec = objShell.Exec(strCommand)
If Err.Number <> 0 Then
    WScript.Echo "Problem with command"
    WScript.Quit(1)
End If

Do While objExec.Status = 0
    WScript.Sleep 100
Loop

intReturnCode = objExec.ExitCode

For Each intSuccessCode In arrSuccessCodes
    If CInt(intSuccessCode) = intReturnCode Then
        WScript.Quit(0)
    End If
Next

WScript.Quit(intReturnCode)

No comments yet

Comments are moderated and appear once approved.