簡體   English   中英

如何使用NSIS安裝較新版本的軟件之前先卸載較舊版本的軟件

[英]How to uninstall older version of the software before installing the newer version using NSIS

我正在使用NSIS創建新的軟件安裝程序。 在使用NSIS之前,我們使用WIX安裝程序來創建相同的安裝程序包。

我的要求是,當我們使用NSIS安裝較新版本的安裝程序(例如EMR 4.0)時,如果存在任何用WIX安裝程序創建的較舊版本的安裝程序(例如EMR 3.0),則應刪除較舊的版本在安裝新版本的安裝程序之前,請先進行安裝。

為此,我在.Oninit中編寫了以下代碼片段,但它不起作用

ReadRegStr $R0 HKLM "SOFTWARE\CPS\PowerChute Personal Edition\3.01.00" "InstallPath"

在上面的行中,我傳遞的第一個參數來自Windows注冊表。

第二個參數“ InstallPath”是安裝路徑的目錄位置:C:\\ Program Files \\ CPS \\ PowerChute Personal Edition \\

Pop $0;
${If} $0 <> 0
MessageBox MB_ICONSTOP "Reading Registry Failed, error $0"
${Else}
MessageBox MB_OKCANCEL "Reading the Registry $R0"

在這里,它將轉到其他部分並顯示消息:“讀取注冊表C:\\ Program Files \\ CPS \\ PowerChute Personal Edition \\”

然后,我添加了以下代碼,但在IDOK處顯示錯誤:“ Invalid command:” IDOK“

IDOK uninst
    Abort
    ${EndIf}
    uninst:
    Exec $R0\uninst.exe
    done:

我想知道,這是卸載的正確方法嗎? “ Exec $ R0 \\ uninst.exe”真的有效嗎?

我們還可以使用$ {If} $ R0 <>“”檢查路徑是否為空嗎?

請幫助我,請給出您的想法。

下面是更新的代碼:

ReadRegStr $R0 HKLM "SOFTWARE\CPS\PowerChute Personal Edition\3.01.00" "InstallPath"

${If} $R0 != ""
MessageBox MB_OKCANCEL "Powerchute is already installed. Remove the pervious version"
ExecWait '"$R0\uninst.exe"'
${Else}
MessageBox MB_OKCANCEL "Powerchute is not installed"

${EndIf}

是否可以在If條件下直接在MessageBox下方使用ExecWait'“ $ R0 \\ uninst.exe”'。

更新了鱈魚以適應新要求:

我的新要求是,如果IF條件為true,則在下面的.onInit函數中,而不是顯示MessageBox,我需要顯示一個對話框,在其中我具有諸如“更改,修復或刪除安裝”,“刪除”按鈕和一些文本的標題。 當我單擊“刪除”按鈕時,它應該會卸載。 我已經寫了一些代碼,但是請幫助我完成它。

Page custom MyPageCreate

Function .onInit

ReadRegStr $R0 HKLM "SOFTWARE\APC\PowerChute Personal Edition\3.01.00" "InstallPath"

${If} $R0 != ""
;MessageBox MB_OKCANCEL "Powerchute is already installed in $R0 Remove the ;pervious version?" IDOK uninst

; HERE I SHOULD CALL THE FUNCTION
MyPageCreate

Abort
uninst:

ExecWait '"MsiExec.exe" /X{8ED262EE-FC73-47A9-BB86-D92223246881}'

${Else}
MessageBox MB_OKCANCEL "Not intalled"

${EndIf}

FunctionEnd

Var Text

Below is the function:

Function MyPageCreate
nsDialogs::Create 1018
Pop $0

${NSD_CreateLabel} 0 0 100% 12u "Change, repair, or remove installation"
Pop $0


${NSD_CreateText} 0 13u 100% -13u "Type something here..."
    Pop $Text

**** Here I need to give the remove button **********

nsDialogs::Show
FunctionEnd

ReadRegStr不會壓入堆棧, Pop $0沒有意義。 如果您想知道如何檢測指令是否失敗,應查閱文檔。 ReadRegStr設置錯誤標志,並在失敗時返回"" (空字符串)。

IDOK不是指令,而是與MessageBox使用的關鍵字。 從某處復制代碼時,您可能會犯錯。

Exec $R0\\uninst.exe可能有效,具體取決於卸載程序的編寫方式,沒有通用答案。 但是,我建議您使用ExecWait '"$R0\\uninst.exe"'代替。

您不能使用<> ""來檢查字符串是否為空,因為<>是數字,請使用${If} $R0 != "" LogicLib.nsh列出了可用的運算符。

ReadRegStr $R0 HKLM "SOFTWARE\CPS\PowerChute Personal Edition\3.01.00" "InstallPath"
${If} $R0 != ""
  MessageBox MB_OKCANCEL "Powerchute is already installed. Remove the pervious version?" IDOK uninst
  Abort
uninst:
  ExecWait '"$R0\uninst.exe"'
${Else}
  MessageBox MB_OK "Powerchute is not installed"
${EndIf}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM