English 中文(简体)
如何要求用户使用NSIS卸载以前的版本
原标题:
  • 时间:2009-04-05 20:31:17
  •  标签:

I have just started using NSIS.
It works very well but I find the documentation a bit unstructured. How do I require user to uninstall previous version before installing a new version with NSIS?

NSIS(Nullsoft Scriptable Install System)是一个用于创建Windows安装程序的开源系统。

最佳回答

NSIS是一个很棒的Windows安装程序。以下是我如何在安装同一应用程序的新版本时使用NSIS卸载当前版本。将以下函数添加到NSIS脚本中。

Function .onInit

         Exec $INSTDIRuninst.exe 

FunctionEnd

您也可以查看NSIS wiki上的“在安装新的之前自动卸载旧的”链接。

问题回答

另一种方法是使UninstallPrevious部分隐藏,并使其在安装程序中的所有其他部分之前运行。我还建议让卸载程序静默运行。

; The "" makes the section hidden.
Section "" SecUninstallPrevious

    Call UninstallPrevious

SectionEnd

Function UninstallPrevious

    ; Check for uninstaller.
    ReadRegStr $R0 HKLM "${HKLM_REG_KEY}" "InstallDir"

    ${If} $R0 == ""        
        Goto Done
    ${EndIf}

    DetailPrint "Removing previous installation."    

    ; Run the uninstaller silently.
    ExecWait  "$R0Uninstall.exe /S" 

    Done:

FunctionEnd

这种方法的优点是,用户在准备好安装新版本之前不会卸载旧版本。此外,他们甚至不必决定是否卸载旧版本,它只是神奇地消失了。

当然,根据您的需要,您可能希望用户确认卸载,在这种情况下使用spinner_den方法。

我重用在安装过程中写入的UninstallStringQuietUninstallString注册表项,以便稍后确定卸载程序命令。

一对夫妇在顶部定义:

!define PROJECT_REG_UNINSTALL_KEY "SoftwareMicrosoftWindowsCurrentVersionUninstall${PROJECT_NAME}"
!define PROJECT_UNINSTALL_EXE "uninstall.exe"

在安装程序部分中:

WriteRegStr HKLM "${PROJECT_REG_UNINSTALL_KEY}" "UninstallString"  "$INSTDIR${PROJECT_UNINSTALL_EXE}" _?=$INSTDIR 
WriteRegStr HKLM "${PROJECT_REG_UNINSTALL_KEY}" "QuietUninstallString"  "$INSTDIR${PROJECT_UNINSTALL_EXE}" /S _?=$INSTDIR 

然后在.onit中获取注册表项值(如果你的应用程序已经以这种方式安装,则会存在)并运行它:

${If} ${Silent}
    ReadRegStr $R0 HKLM "${PROJECT_REG_UNINSTALL_KEY}" "QuietUninstallString"
${Else}
    ReadRegStr $R0 HKLM "${PROJECT_REG_UNINSTALL_KEY}" "UninstallString"
${EndIf}
ExecWait "$R0"




相关问题
热门标签