简体   繁体   English

在安装新版本之前卸载以前的安装程序时,如何使用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

Once installed the application using NSIS, To uninstall it from the Control Panel written the below script 使用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

So that while uninstalling, first shows the pop-up message ("Are you sure you want to uninstall EMR?") When clicked on "OK", uninstallation completes. 因此,在卸载时,首先显示弹出消息(“确定要卸载EMR吗?”)。单击“确定”时,卸载完成。

And also to uninstall the installed software before installing it again, written the below script. 还要在重新安装之前卸载已安装的软件,请编写以下脚本。

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

In the above script i have not used ExecWait "$INSTDIR\\uninstall.exe /S", because I wanted to show the uninstallation process to the user. 在上面的脚本中,我没有使用ExecWait“ $ INSTDIR \\ uninstall.exe / S”,因为我想向用户显示卸载过程。

But here how to hide the message "Are you sure you want to uninstall EMR?" 但是,这里如何隐藏消息“您确定要卸载EMR吗?” that is popping up from un.onInit? 从un.onInit弹出?

When uninstalling MSI, we are using "/qb" to hide the message. 卸载MSI时,我们使用“ / qb”隐藏消息。 Like this is there any way to hide the message using NSIS? 像这样,有没有办法使用NSIS隐藏消息?

A MessageBox can be skipped when using /S but without it you have to make your own detection logic: 使用/ S时,可以跳过MessageBox但是如果没有它,则必须自己制定检测逻辑:

!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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 由于UAC,NSIS安装程序.onInit和un.onInit运行两次 - NSIS installer .onInit and un.onInit run twice because of UAC NSIS - 如何覆盖“un.onInit”回调 - NSIS - How to override "un.onInit" callback 使用NSIS在安全模式下卸载时,如何停止卸载并弹出消息框? - How to stop the uninstallation and pop up a message box when uninstalling in Safe mode using NSIS? NSIS卸载程序不运行un.onInit - NSIS uninstaller doesn't run un.onInit 在使用 NSIS 卸载 Windows 安装程序时,我需要在卸载程序屏幕之前提示一个消息框(您确定要卸载吗?) - While Uninstalling windows installer using NSIS, i need to prompt a message box (Are you sure you want to uninstall.?) before the uninstaller screen 使用NSIS卸载以前的Wix安装程序时,将花费更长的时间,并且应用程序标题栏显示“ Not Responding” - When Uninstalling the previous Wix installer using NSIS it is taking longer time and the application title bar is showing “Not Responding” 卸载时未从 NSIS 安装程序调用 DLL 函数 - DLL Function is not calling from the NSIS installer when uninstalling 卸载 NSIS 安装程序时如何更改位图图像 - How to change the bitmap image when uninstalling the NSIS installer (Un)在WIX Burn安装程序中安装NSIS软件包 - (Un)Installing NSIS packages in WIX Burn installer 安装使用NSIS开发的软件时,如果在服务器操作系统中安装,应如何抛出弹出消息 - When installing the software that was developed using NSIS, how should I throw a pop-up message if installing in server operating systems
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM