- NSIS Discussion
- Set silent installer exit code?
Archive: Set silent installer exit code?
BSOD2600
19th October 2009 07:23 UTC
Set silent installer exit code?
How does one set a unique exit code/error level and/or error message when using the silent installer feature? I've already searched and found the following:
* How to set exit errorlevel code
* Error Level when installer ends
Neither threads had clear solutions to this problem. I've tried a bunch of various code trying to abort/quit in .onInit and other custom page functions. None appear to set the dos errorlevel (or if it does, its 9009 which clearly isn't my custom errorlevel).
Basically, I'm passing in a silent install configuration file, parsing it out for the stuff I need, running checks on the data the user provided and then if need be, quit the installer with unique error codes/messages depending what is wrong. I realize while one can display a Messagebox for the error, that sort of defeats the purpose of a "silent installer".
Suggestions?
MSG
19th October 2009 09:01 UTC
In the thread you linked, kickik said you can't set your own exit code in NSIS.
ChocJunkie
19th October 2009 09:23 UTC
Originally posted by MSG
In the thread you linked, kickik said you can't set your own exit code in NSIS.
For what reason does SetErrorLevel exist, if it's not possible to set a own exit code? Especially because the manual says so:
http://nsis.sourceforge.net/Docs/AppendixD.html#D.1CJ
BSOD2600
19th October 2009 11:12 UTC
Originally posted by ChocJunkie
For what reason does SetErrorLevel exist, if it's not possible to set a own exit code? Especially because the manual says so: http://nsis.sourceforge.net/Docs/AppendixD.html#D.1
CJ
I agree and saw it in the manual too, but am unable to actually have it work.
Would you please provide sample code demonstrating it working?
MSG
19th October 2009 12:46 UTC
Originally posted by ChocJunkie
For what reason does SetErrorLevel exist, if it's not possible to set a own exit code? Especially because the manual says so: http://nsis.sourceforge.net/Docs/AppendixD.html#D.1
CJ
Hmmm. Fair enough. :) To use that, I'd try putting IfSilent into .onGuiEnd or something like that.
BSOD2600
19th October 2009 18:31 UTC
Originally posted by MSG
Hmmm. Fair enough. :) To use that, I'd try putting IfSilent into .onGuiEnd or something like that.
http://nsis.sourceforge.net/Docs/Chapter4.html#4.12When an installer or an uninstaller is silent, not all callback functions are called. .onGUIInit, .onGUIEnd, their uninstaller equivalents and any callback related to a specific page or page type will not be called.
MSG
20th October 2009 12:27 UTC
.oninstsuccess and .oninstfailed then? Or just at the end of the last section.
BSOD2600
20th October 2009 14:04 UTC
Originally posted by BSOD2600
I agree and saw it in the manual too, but am unable to actually have it work.
Would you please provide sample code demonstrating it working?
pengyou
20th October 2009 17:02 UTC
I tried modifying the MUI2 'Basic.nsi' example to return an error code. When I ran it using /S on the command-line it returned the correct error code.
I don't understand your problem; perhaps because you have not supplied enough information? For example: How are you making your installer silent?
BSOD2600
20th October 2009 18:44 UTC
I'm making the installer silent via the /S command.
Alright, so taking your basic.nsi example, I modified it to set an error level and it doesn't appear to work. Would you please post your sample code?
C:\Program Files\NSIS\Examples\Modern UI>%errorlevel%
'9009' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files\NSIS\Examples\Modern UI>Basic.exe /S
C:\Program Files\NSIS\Examples\Modern UI>%errorlevel%
'9009' is not recognized as an internal or external command,
operable program or batch file.
----------------------
basic.nsi
;--------------------------------
;Include Modern UI
!include "MUI2.nsh"
;--------------------------------
;General
;Name and file
Name "Modern UI Test"
OutFile "Basic.exe"
;Default installation folder
InstallDir "$LOCALAPPDATA\Modern UI Test"
;Get installation folder from registry if available
InstallDirRegKey HKCU "Software\Modern UI Test" ""
;Request application privileges for Windows Vista
RequestExecutionLevel user
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;--------------------------------
;Pages
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Installer Sections
Section "Dummy Section" SecDummy
IfSilent 0 +4
SetErrorLevel 1234
Abort
SetOutPath "$INSTDIR"
;ADD YOUR OWN FILES HERE...
;Store installation folder
WriteRegStr HKCU "Software\Modern UI Test" "" $INSTDIR
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
;--------------------------------
;Descriptions
;Language strings
LangString DESC_SecDummy ${LANG_ENGLISH} "A test section."
;Assign language strings to sections
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Uninstaller Section
Section "Uninstall"
;ADD YOUR OWN FILES HERE...
Delete "$INSTDIR\Uninstall.exe"
RMDir "$INSTDIR"
DeleteRegKey /ifempty HKCU "Software\Modern UI Test"
SectionEnd
What I really want to do, is to read in the silent answer file, parse it to check for issues and then throw various error codes/messages based before the installer actually gets to installing...
pengyou
20th October 2009 19:09 UTC
I think I see what the problem is:
C:\Program Files\NSIS\Examples\Modern UI>Basic.exe /S
C:\Program Files\NSIS\Examples\Modern UI>%errorlevel%
'9009' is not recognized as an internal or external command,
operable program or batch file.
Try using a batch file to display the errorlevel. Here is what I used to test my script:
test >type silent-demo.bat
@echo off
echo Run 'silent-mui-demo.exe' silently by supplying /S on command line
silent-mui-demo.exe /S
echo 'silent-mui-demo.exe /S' returned %ERRORLEVEL%
echo.
test >silent-demo
Run 'silent-mui-demo.exe' silently by supplying /S on command line
'silent-mui-demo.exe /S' returned 1500
test >
"1500" is the expected value when the script is run silently. My script is attached.
BSOD2600
20th October 2009 19:37 UTC
Well heck, that made it easy and my existing code does work after all. Guess my validation was wrong the whole time.
Thanks!