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}
You almost got it