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

How to know which uninstaller has been invoked if multiple uninstallers are present

我需要创建两个名称不同的卸载程序。每个都会删除不同的文件夹。我正在使用相同的 project/script 来创建卸载程序。如何找到用户调用了哪个卸载程序?以便我可以在 un.onInit 中使用该值并删除相应的文件夹?

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

安装者:

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} [=11=]
${GetBaseName} [=11=] [=11=] ; Remove path and extension
${If} [=11=] == "OtherUninst"
    RMDir "Other"
${Else}
    RMDir "Normal"
${EndIf}
SectionEnd

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

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

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

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

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