我有一个应用程序可以在同一台计算机上由同一用户多次安装,并根据其中的设置采取不同的行为。如何制作可多次安装的NSIS安装程序?
我该如何制作一个安装程序,允许多个安装同一个应用程序?默认情况下,我所做的基本脚本允许我在不同的文件夹中多次安装,但在控制面板中,我只能看到要卸载的最后一个版本(我认为它是因为InstallDirRegKey)。
我有一个应用程序可以在同一台计算机上由同一用户多次安装,并根据其中的设置采取不同的行为。如何制作可多次安装的NSIS安装程序?
我该如何制作一个安装程序,允许多个安装同一个应用程序?默认情况下,我所做的基本脚本允许我在不同的文件夹中多次安装,但在控制面板中,我只能看到要卸载的最后一个版本(我认为它是因为InstallDirRegKey)。
这是一个相当奇怪的要求,大多数应用程序不以这种方式工作,只是在控制面板中显示上次安装的实例,因为每次安装时都会覆盖注册表中的条目。
要在你需要使用一个唯一的键名在注册表中的每个卸载进入控制面板上显示多个条目:
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
InstallDirRegKey无关与显示在控制面板。如果您希望在不同位置进行多次安装,则不应使用InstallDirRegKey。 – Anders