2016-02-26 160 views
0

我有一個應用程序可以在同一臺計算機上由同一用戶多次安裝,並根據其中的設置採取不同的行爲。如何製作可多次安裝的NSIS安裝程序?

我該如何製作一個安裝程序,允許多個安裝同一個應用程序?默認情況下,我所做的基本腳本允許我在不同的文件夾中多次安裝,但在控制面板中,我只能看到要卸載的最後一個版本(我認爲它是因爲InstallDirRegKey)。

+0

InstallDirRegKey無關與顯示在控制面板。如果您希望在不同位置進行多次安裝,則不應使用InstallDirRegKey。 – Anders

回答

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 
+0

thx,不知道簡單地寫入註冊表我可以使應用程序顯示爲已安裝。雖然有意義。現在有一個問題:爲什麼需要執行StrCmp + badInstallId?我應該執行註冊表項以破壞嗎? – Quamis

+0

註冊表不會被破壞,但用戶可能會刪除.ini來「清理」他們的計算機! – Anders

+0

:))是true。感謝您的解釋 – Quamis