TLDR:
I'd like to know if it's possible if winst32.exe will return an exitcode to the Windows command interpreter, which is equal to the value of $ExitCode$ from the opsi-winst script (setup.ins), if the setup.ins is being run in the following fashion:
Code: Alles auswählen
winst32.exe /silent <package-path>\setup.ins
We have made an unattended Windows 7 setup, whereby we use a batch script that installs packages using opsi-winst during deployment:
The batch script has built-in errorhandling that checks the error return code and acts accordingly, ie terminate script and log any errors. However the issue is that winst32.exe always seems to return an errorcode 0. In other words it always "succeeds", making proper errorhandling difficult.
Example batchscript:
Code: Alles auswählen
@ECHO OFF
SET ERR_LVL1=0
SET ERR_LVL2=0
"c:\program files (x86)\opsi.org\opsi-client-agent\opsi-winst\winst32.exe" /silent \\opsi.example.com\opsi_depot\thisfolderexistsontheopsiserver\setup.ins
SET ERR_LVL1=%ERRORLEVEL%
ECHO %ERR_LVL1%
"c:\program files (x86)\opsi.org\opsi-client-agent\opsi-winst\winst32.exe" /silent \\opsi.example.com\opsi_depot\thisfolderDOESNOTexistontheopsiserver\setup.ins
SET ERR_LVL2=%ERRORLEVEL%
ECHO %ERR_LVL2%
0
0
Where I would normally expect output similar like this:
0
9009 (unable to locate file)
Below are sample build packagescripts we use:
Sample setup.ins, this script is basically an opsi wrapper that calls a batch script Install_Package.cmd, which performs the actual installation. The exitcode returned by Install_package.cmd is offcourse trapped with the function [sub_check_exitcode]
Code: Alles auswählen
[Initial]
ExitOnError=true
StayOnTop = true
[Actions]
requiredWinstVersion >= "4.10.5"
DefVar $ProductId$
DefVar $ExitCode$
DefVar $NTVersioninfo$
DefVar $32bitfile$
SetLogLevel=6
; ----------------------------------------------------------------
Set $ProductId$ = "Package"
; ----------------------------------------------------------------
Message "Doing stuff"
; OS Version ermitteln > Win2000
Set $NTVersioninfo$ = GetMsVersionInfo
if not ( $NTVersioninfo$ >= "5.1" )
LogError "Windows version is not compatible"
isFatalError
endif
DosInAnIcon_1
sub_check_exitcode
[DosInAnIcon_1]
%scriptpath%\depot\Install_Package.cmd
[sub_check_exitcode]
comment "test for installation success via exit code"
set $ExitCode$ = getLastExitCode
; informations to exit codes see
; http://msdn.microsoft.com/en-us/library/aa372835(VS.85).aspx
; http://msdn.microsoft.com/en-us/library/aa368542.aspx
if ($ExitCode$ = "0")
comment "looks good: setup program gives exitcode zero"
else
comment "Setup program gives a exitcode unequal zero: "+$ExitCode$
if ($ExitCode$ = "1605")
comment "ERROR_UNKNOWN_PRODUCT 1605 This action is only valid for products that are currently installed."
comment "Uninstall of a not installed product failed - no problem"
else
if ($ExitCode$ = "1641")
comment "looks good: setup program gives exitcode 1641"
comment "ERROR_SUCCESS_REBOOT_INITIATED 1641 The installer has initiated a restart. This message is indicative of a success."
Exitwindows /Reboot
else
if ($ExitCode$ = "3010")
comment "looks good: setup program gives exitcode 3010"
comment "ERROR_SUCCESS_REBOOT_REQUIRED 3010 A restart is required to complete the install. This message is indicative of a success."
Exitwindows /Reboot
else
logError "Fatal: Setup program gives an unknown exitcode unequal zero: "+$ExitCode$
isFatalError
endif
endif
endif
endif
Code: Alles auswählen
@Echo off
CLS
SETLOCAL
::---------------------------------------------------------------------------------------------------------------------------------------
:: Installs Something
::---------------------------------------------------------------------------------------------------------------------------------------
COLOR 40
ECHO DO NOT CLOSE ANY WINDOWS UNTILL YOU SEE THE CTRL+ALT+DEL SCREEN!!!!
SET PACKAGEDIR=%~dp0
SET PACKAGEDIR=%PACKAGEDIR:~,-1%
SET ERR_LVL2=0
SET ERR_LVL=0
SET ERR_LVL_SCRIPTS=0
SET ERR_LVL_TMP=0
SET ERR_LVL_TOOLS=0
SET CMDNAME=%~nx0
SET CMDNAME=%cmdName:~,-4%
IF NOT EXIST "C:\TMP\APPS." MKDIR C:\TMP\APPS\
SET LOGFILE=C:\TMP\APPS\%CMDNAME%_%RANDOM%
IF NOT EXIST "C:\TOOLS." MKDIR C:\TOOLS
CALL :LOGIT Start %CMDNAME%
CALL :LOGIT PACKAGEDIR=%PACKAGEDIR%
::=========================================================================
:MAINPROG
::=========================================================================
CALL :LOGIT Installing Some Innosetup package
%PACKAGEDIR%\package_1.1.0_setup.exe /NOCANDY /LOADINF="%PACKAGEDIR%\settings.inf" /SILENT /NORESTART /SP-
SET ERR_LVL2=%ERRORLEVEL%
IF %ERR_LVL%==0 SET ERR_LVL=%ERR_LVL2%
IF /I %ERR_LVL% NEQ 0 (
IF /I %ERR_LVL% NEQ 3010 GOTO :MAINPROG_EXIT
)
:MAINPROG_EXIT
CALL :LOGIT Einde installatie
GOTO :EINDE
::=========================================================================
:EINDE
::=========================================================================
CALL :LOGIT einde ERROR=%ERR_LVL%
EXIT /B %ERR_LVL%
::=========================================================================
:LOGIT
::=========================================================================
SET LOGTIME=%TIME%
SET LOGTIME=%LOGTIME:~,-3%
ECHO %*
ECHO %DATE% %LOGTIME% %* >> %LOGFILE%.txt
:EXIT_LOGIT
GOTO :EOF
Code: Alles auswählen
winst32.exe /silent <package-path>\setup.ins
regards,
Ritch