如何制作可多次安装的NSIS安装程序?

时间:2016-02-26 15:06:19

标签: windows nsis

我有一个可以由同一个用户在同一台​​计算机上多次安装的应用程序,并根据其中的设置采取不同的行动。

如何制作允许多次安装相同应用的安装程序?默认情况下,我制作的基本脚本允许我在不同的文件夹中多次安装,但在控制面板中我只能看到要卸载的最后一个版本(我想它是因为InstallDirRegKey)。

1 个答案:

答案 0 :(得分:0)

这是一个相当奇怪的要求,大多数应用程序不能以这种方式工作,只是在控制面板中显示最后安装的实例,因为每次安装时都会覆盖注册表中的条目。

要在控制面板中显示多个条目,您需要为注册表中的每个卸载条目使用唯一的密钥名称:

Var InstallId
RequestExecutionLevel user

Section
System::Call 'OLE32::CoCreateGuid(&g16.s)'
Pop $InstallId
SetOutPath "$InstDir"
WriteIniStr "$InstDir\Uninst.ini" "Setup" "InstallId" $InstallId ; Store the id somewhere so we know which registry key to delete
WriteUninstaller "$InstDir\Uninst.exe"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\$InstallId" DisplayName "$(^Name) ($InstDir)"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\$InstallId" UninstallString '"$InstDir\Uninst.exe"'
SectionEnd

Section Uninstall
ReadIniStr $InstallId "$InstDir\Uninst.ini" "Setup" "InstallId"
StrCmp $InstallId "" 0 +2
StrCpy $InstallId "$(^Name):BadInstallId" ; Set to some invalid id so we don't delete the wrong registry key if the .ini has been corrupted
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\$InstallId"

Delete "$InstDir\Uninst.ini"
Delete "$InstDir\Uninst.exe"
RMDir "$InstDir"
SectionEnd