在NSIS中制作安装程序/重新安装程序

时间:2015-06-10 06:20:36

标签: nsis

我需要这个例程 - 如果出现带有安装路径的RegKey,我们必须停止执行的应用程序(如果执行),静默启动卸载程序(如果找不到卸载程序 - 只删除目录中的所有文件)并将INSTDIR设置为value来自Registry。 如果RegKEy with Installation Path不存在 - 启动正常安装。

; Try to read Install Path from Reg
ReadRegStr $0 HKCU "Software\TelnetTray" "Path"

; Uninstall first if app installed
${If} $0 != ""
  !define INSTDIR $0

  ; Try to stop app if executed
  Stop "$INSTDIR\app.exe"

  ; Try to uninstall
  ${If} ${FIleExists} "$INSTDIR\uninst.exe"
    ExecWait "$INSTDIR\uninst.exe /S"
  ; Or just delete all files in INSTDIR
  ${Else}
    Delete "$INSTDIR\*"
  ${EndIf}
${EndIf}

1 个答案:

答案 0 :(得分:0)

你几乎得到了它

; Try to read Install Path from Reg
ReadRegStr $0 HKCU "Software\TelnetTray" "Path"

; Uninstall first if app installed
${If} $0 != ""
  StrCpy $INSTDIR $0

  ; Try to stop app if executed
  ${nsProcess::CloseProcess} "$INSTDIR\app.exe" $R0

  ; Try to uninstall
  ${If} ${FIleExists} "$INSTDIR\uninst.exe"
    ExecWait "$INSTDIR\uninst.exe /S"
  ; Or just delete all files in INSTDIR
  ${Else}
    RMDir /r "$INSTDIR"
  ${EndIf}
${EndIf}