Making installer/reinstaller in NSIS

77 views Asked by At

I need this routine - if RegKey with Installation Path is presented, we must to stop executed application (if executed), start Uninstaller silently (if uninstaller is not found - just delete all files in the directory) and set INSTDIR to value from Registry. If RegKEy with Installation Path is not exists - start normal installation.

; 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

There are 1 answers

2
Francisco R On

You almost got it

; 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}