在安装新安装程序之前卸载以前的安装程序时如何使用 NSIS 隐藏从 un.onInit 弹出的消息框

巴维亚

使用 NSIS 安装应用程序后,要从控制面板卸载它,请编写以下脚本

Function un.onInit
    MessageBox MB_YESNO|MB_ICONEXCLAMATION "Are you sure you want to uninstall EMR?" /SD IDYES IDYES NoAbort
    Abort 
    NoAbort:
    SetAutoClose true

FunctionEnd

因此,在卸载时,首先显示弹出消息(“您确定要卸载 EMR?”) 单击“确定”后,卸载完成。

并且在再次安装之前卸载已安装的软件,编写了以下脚本。

Function RemovePrevVerFunction

ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EMR"  "UninstallString" 

 ${If} $R0 != ""
 MessageBox MB_OKCANCEL "EMR is already installed. Do you want to remove the previous version?" IDOK uninst
 Abort
 uninst:
 ExecWait "$INSTDIR\uninstall.exe"
 Quit
FunctionEnd

在上面的脚本中,我没有使用 ExecWait "$INSTDIR\uninstall.exe /S",因为我想向用户展示卸载过程。

但是这里如何隐藏消息“您确定要卸载 EMR?” 那是从 un.onInit 弹出的?

卸载 MSI 时,我们使用“/qb”来隐藏消息。像这样有没有办法使用 NSIS 隐藏消息?

不同的

MessageBox使用 /S 时可以跳过A,但如果没有它,您必须制作自己的检测逻辑:

!include LogicLib.nsh
!include FileFunc.nsh

InstallDir "$ProgramFiles\Test"

Page Directory
Page InstFiles

Function GetAppFromCommand
Exch $1
Push $2
StrCpy $2 $1 1 0
StrCmp $2 '"' 0 done
Push $3
StrCpy $3 ""
loop:
    IntOp $3 $3 + 1
    StrCpy $2 $1 1 $3
    StrCmp $2 '' +2
    StrCmp $2 '"' 0 loop
    StrCpy $1 $1 $3
    StrCpy $1 $1 "" 1 ; Remove starting quote
Pop $3
done:
Pop $2
Exch $1
FunctionEnd
!macro GetAppFromCommand in out
Push "${in}"
Call GetAppFromCommand
Pop ${out}
!macroend

!macro UninstallPreviousNSIS UninstCommand CustomParameters
Push $0
Push $1
Push $2
Push '${CustomParameters}'
Push '${UninstCommand}'
Call GetAppFromCommand ; Remove quotes and parameters from UninstCommand 
Pop $0
Pop $1
GetFullPathName $2 "$0\.."
ExecWait '"$0" $1 _?=$2'
Delete "$0" ; Extra cleanup because we used _?=
RMDir "$2"
Pop $2
Pop $1
Pop $0
!macroend

Function .onInit
ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "UninstallString"
${If} $R0 != ""
    MessageBox MB_YESNO|MB_ICONQUESTION "$(^Name) is already installed. Do you want to remove the previous version?" IDNO noUninstOld
    !insertmacro UninstallPreviousNSIS $R0 "/NoMsgBox"
    noUninstOld:
${EndIf}
FunctionEnd

Section
SetOutPath $InstDir
File "/oname=$InstDir\Dummy.txt" "${__FILE__}"
WriteUninstaller "$InstDir\Uninst.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "UninstallString" '"$InstDir\Uninst.exe"'
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" "DisplayName" "$(^Name)"
SectionEnd

Function un.onInit
${GetParameters} $0
ClearErrors
${GetOptions} "$0" "/NoMsgBox"  $1
${IfNotThen} ${Errors} ${|} Goto NoAbort ${|}
MessageBox MB_YESNO|MB_ICONEXCLAMATION "Are you sure you want to uninstall $(^Name)?" /SD IDYES IDYES NoAbort
Abort 
NoAbort:
FunctionEnd

Section Uninstall
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
Delete "$InstDir\Dummy.txt"
Delete "$InstDir\Uninst.exe"
RMDir "$InstDir"
SectionEnd

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档