如果存在多个卸载程序,如何知道调用了哪个卸载程序

时间:2015-08-04 07:13:07

标签: nsis

我需要创建两个具有不同名称的卸载程序。每个将删除不同的文件夹。我使用相同的项目/脚本来创建卸载程序。如何找到用户调用的卸载程序?这样我可以在un.onInit中使用该值并删除相应的文件夹吗?

同样,如果同一个脚本正在创建两个安装程序,那么如何找到用户调用的安装程序?

2 个答案:

答案 0 :(得分:2)

<强>安装程序:

Section
!ifdef INSTALLER_OTHER
DetailPrint "Other"
!else
DetailPrint "Normal"
!endif
SectionEnd

使用makensis.exe /DINSTALLER_OTHER setup.nsi

生成其他安装程序

<强>卸载程序:

您可以检查卸载程序文件名:

!include FileFunc.nsh
!include LogicLib.nsh
Section un.Whatever
${GetExeName} $0
${GetBaseName} $0 $0 ; Remove path and extension
${If} $0 == "OtherUninst"
    RMDir "Other"
${Else}
    RMDir "Normal"
${EndIf}
SectionEnd

或者安装程序可以编写您检查的特殊文件。

或者在卸载程序中嵌入特殊数据:

InstallDir "$Temp\TestInst"
!include LogicLib.nsh
Section
SetOutPath $InstDir
WriteUninstaller "$InstDir\Uninst.exe"
FileOpen $0 "$InstDir\Uninst.exe" a
FileSeek $0 0 END
!ifdef INSTALLER_OTHER
FileWriteByte $0 1
!else
FileWriteByte $0 0
!endif
FileClose $0
SectionEnd

Section -Uninstall
FileOpen $0 "$EXEPATH" r
FileSeek $0 -1 END
FileReadByte $0 $1
FileClose $0
${If} $1 = 1
    RMDir "Other"
${Else}
    RMDir "Normal"
${EndIf}
SectionEnd

答案 1 :(得分:0)

通过添加Anders解决方案,您可以使用注册表写入读取方法。它将是一个快速操作,即每当您运行任何卸载程序时,只需编写一个注册表值并设置它的值。之后,您只需要阅读该注册表值并进行相应处理。

相关问题