在這個小NSIS安裝,我想在內部設置錯誤級別和外部抓住它(當我運行一個批處理腳本中靜默模式安裝/卸載),但不知何故,我總是%ERRORLEVEL% = 0NSIS靜默卸載SetErrorLevel
這裏是我的NSI腳本
!addincludedir .\include
!include StrRep.nsh
!include ReplaceInFile.nsh
!include LogicLib.nsh
!include FileFunc.nsh
!insertmacro GetParameters
!insertmacro GetOptions
!define MY_APP_NAME "foo"
Outfile "${MY_APP_NAME}.exe"
InstallDir $DESKTOP
Section
${GetParameters} $R0
ClearErrors
${GetOptions} $R0 /PLACEHOLDER= $0
IfErrors 0 +2
Call ErrorHandler
SetOutPath $INSTDIR
File /r foo_root_folder
!insertmacro _ReplaceInFile "foo_root_folder\subfolder_a\test.properties" "%%placeholder_string%%" "$0"
WriteRegStr HKLM "SOFTWARE\${MY_APP_NAME}" "Install_Dir" "$INSTDIR\foo_root_folder"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MY_APP_NAME}" "Publisher" "Federico"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MY_APP_NAME}" "DisplayName" "${MY_APP_NAME}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MY_APP_NAME}" "DisplayVersion" "1.0"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MY_APP_NAME}" "UninstallString" '"$INSTDIR\foo_root_folder\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MY_APP_NAME}" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MY_APP_NAME}" "NoRepair" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MY_APP_NAME}" "EstimatedSize" 1000
WriteUninstaller "foo_root_folder\uninstall.exe"
SectionEnd
Section "Uninstall"
ReadRegStr $0 HKLM "SOFTWARE\${MY_APP_NAME}" "Install_Dir"
${If} ${Errors}
Call un.ErrorHandler
${Else}
${IF} $0 == ""
Call un.ErrorHandler
${ELSE}
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MY_APP_NAME}"
DeleteRegKey HKLM "SOFTWARE\${MY_APP_NAME}"
RmDir /r /REBOOTOK "$0"
${ENDIF}
${EndIf}
SectionEnd
Function ErrorHandler
SetErrorLevel 1
Quit
FunctionEnd
Function un.ErrorHandler
SetErrorLevel 1
Quit
FunctionEnd
有什麼不對的呢?我認爲,這些線(在錯誤的情況下)我應該%ERRORLEVEL%= 1
SetErrorLevel 1
Quit
例如:安裝後,我特意刪除註冊表項「HKLM \ SOFTWARE \ $ {MY_APP_NAME}」 ,然後運行卸載程序。它沒有找到問題的關鍵和退出的預期,但%ERRORLEVEL%還是0