在安装新的安装程序之前卸载以前的安装程序时如何使用 NSIS 隐藏从 un.onInit 弹出的消息框
When Uninstalling the previous installer before installing the new how to hide the message box that is popping up from the un.onInit using NSIS
使用 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
以便在卸载时首先显示弹出消息("Are you sure you want to uninstall EMR?")
单击 "OK" 时,卸载完成。
并且在重新安装之前还要卸载已安装的软件,写了下面的脚本。
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",因为我想向用户展示卸载过程。
但是这里如何隐藏从 un.onInit 弹出的消息 "Are you sure you want to uninstall EMR?"?
卸载 MSI 时,我们使用“/qb”来隐藏消息。像这样有没有办法使用 NSIS 隐藏消息?
A MessageBox
可以在使用 /S 时跳过,但如果没有它,您必须制定自己的检测逻辑:
!include LogicLib.nsh
!include FileFunc.nsh
InstallDir "$ProgramFiles\Test"
Page Directory
Page InstFiles
Function GetAppFromCommand
Exch
Push
StrCpy 1 0
StrCmp '"' 0 done
Push
StrCpy ""
loop:
IntOp + 1
StrCpy 1
StrCmp '' +2
StrCmp '"' 0 loop
StrCpy
StrCpy "" 1 ; Remove starting quote
Pop
done:
Pop
Exch
FunctionEnd
!macro GetAppFromCommand in out
Push "${in}"
Call GetAppFromCommand
Pop ${out}
!macroend
!macro UninstallPreviousNSIS UninstCommand CustomParameters
Push [=10=]
Push
Push
Push '${CustomParameters}'
Push '${UninstCommand}'
Call GetAppFromCommand ; Remove quotes and parameters from UninstCommand
Pop [=10=]
Pop
GetFullPathName "[=10=]\.."
ExecWait '"[=10=]" _?='
Delete "[=10=]" ; Extra cleanup because we used _?=
RMDir ""
Pop
Pop
Pop [=10=]
!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} [=10=]
ClearErrors
${GetOptions} "[=10=]" "/NoMsgBox"
${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
使用 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
以便在卸载时首先显示弹出消息("Are you sure you want to uninstall EMR?") 单击 "OK" 时,卸载完成。
并且在重新安装之前还要卸载已安装的软件,写了下面的脚本。
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",因为我想向用户展示卸载过程。
但是这里如何隐藏从 un.onInit 弹出的消息 "Are you sure you want to uninstall EMR?"?
卸载 MSI 时,我们使用“/qb”来隐藏消息。像这样有没有办法使用 NSIS 隐藏消息?
A MessageBox
可以在使用 /S 时跳过,但如果没有它,您必须制定自己的检测逻辑:
!include LogicLib.nsh
!include FileFunc.nsh
InstallDir "$ProgramFiles\Test"
Page Directory
Page InstFiles
Function GetAppFromCommand
Exch
Push
StrCpy 1 0
StrCmp '"' 0 done
Push
StrCpy ""
loop:
IntOp + 1
StrCpy 1
StrCmp '' +2
StrCmp '"' 0 loop
StrCpy
StrCpy "" 1 ; Remove starting quote
Pop
done:
Pop
Exch
FunctionEnd
!macro GetAppFromCommand in out
Push "${in}"
Call GetAppFromCommand
Pop ${out}
!macroend
!macro UninstallPreviousNSIS UninstCommand CustomParameters
Push [=10=]
Push
Push
Push '${CustomParameters}'
Push '${UninstCommand}'
Call GetAppFromCommand ; Remove quotes and parameters from UninstCommand
Pop [=10=]
Pop
GetFullPathName "[=10=]\.."
ExecWait '"[=10=]" _?='
Delete "[=10=]" ; Extra cleanup because we used _?=
RMDir ""
Pop
Pop
Pop [=10=]
!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} [=10=]
ClearErrors
${GetOptions} "[=10=]" "/NoMsgBox"
${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