简体   繁体   中英

how can I make a NSIS installer that can be installed multiple times?

I have an application that can be instlled multiple times on the same computer by the same user, and act differently depending on the settings made in it.

How can i make an installer that would allow multiple installations of the same app? By default the basic script that I've made lets me install multiple times in different folders, but in Control Panel I can only see the last version to uninstall (I suppose its because of InstallDirRegKey).

This is a rather strange requirement, most applications do not work this way and just displays the last installed instance in the control panel because the entry in the registry is overwritten each time you install.

To display multiple entries in the control panel you need to use a unique key name for each uninstall entry in the registry:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM