2013-04-11 73 views
1

我有一個安裝程序,在安裝新版本之前必須卸載以前的版本。當安裝卸載時,NSIS不會中止安裝

但是,當最初的問題被問及它是這樣做的。但卸載對話不。

MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \ 
    "${PRODUCT_NAME} is already installed. $\n$\nIf you have software older than 3.0,  please manually uninstall it with Windows before procedeing. $\n$\nClick `OK` to remove the \ 
    previous version or `Cancel` to cancel this upgrade." \ 
    IDOK uninst IDCANCEL giveup 

; I am giving up 
giveup: 
Abort 

; Run the uninstaller 
uninst: 
ClearErrors 
ExecWait '$R0 _?=$INSTDIR' ;Do not copy the uninstaller to a temp file 
IfErrors no_remove_uninstaller 
no_remove_uninstaller: 
install: 
; ..... snip 

然後在這裏

Function un.onInit 
    MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to  completely remove $(^Name) and all of its components?" IDYES NoAbort 
    Abort 
    NoAbort: 
FunctionEnd 

所以,當它是一個獨立的卸載它似乎是很好,但是當它在開始卸載,如果用戶說否/取消,安裝程序會他們說不行時仍然繼續。我想不出原因。作爲一個不良的副作用,開始菜單上的程序文件圖標是孤立的,並且uninst.exe是孤立的。但是,如果你「手動」運行卸載程序,它似乎很好。除了試圖讓這個東西起作用之外,我沒有改變任何邏輯。

謝謝。

回答

2

它引用的路徑ExecWait然後檢查退出代碼是很重要的:

Function .onInit 
StrCpy $R0 "c:\old install" ; TODO: Somehow find the old install (in the registry? InstallDirRegKey?) and put its path in $R0 
IfFileExists "$R0\*.*" 0 noOldInstall 
    MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "${PRODUCT_NAME} is already installed. blahblah..." IDOK uninstOld 
    Abort 
    uninstOld: 
    ExecWait '"$R0\uninstaller.exe" _?=$R0' $R1 
    ; Exit codes are documented in Appendix D in the help file. 
    StrCmp $R1 0 noOldInstall ; Success? If so we are done... 
    Abort ; Uninstaller was canceled or failed, we cannot continue 
noOldInstall: 
FunctionEnd 
+0

我有這個已經定義: 定義PRODUCT_UNINST_KEY「軟件\微軟\的Windows \ CurrentVersion \卸載\ $ { PRODUCT_NAME}「 – 2013-04-11 20:33:47

+0

對不起,我無法弄清楚如何在註釋中解析新行,但是我應該使用readregstr來獲取路徑嗎? – 2013-04-11 20:43:29

+0

嗯,註冊表本身具有默認密鑰,它是具有可執行文件名稱的完整路徑,但沒有其他程序在列表中執行的路徑密鑰。我可以不使用instdir或其他東西嗎? – 2013-04-11 21:01:51