I'am using NSIS to create a setup for my application and need to check if it's already installed:
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "MyAppInstaller.exe"
InstallDir "$PROGRAMFILES\MyApp"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show
Function .onInit
; Check to see if already installed
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME} ${PRODUCT_VERSION}" "UninstallString"
IfFileExists $R0 +1 NotInstalled
Messagebox MB_ICONQUESTION|MB_YESNO "MyApp 1.0 is already installed.Do you want to uninstall old version" IDNO Quit
Exec $R0
Quit:
Quit
NotInstalled:
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd ...
but nothing happened it always proceed installation and didn't detect the old installed version, did I miss something? I don't know much about NSIS scripting so any help will be appreciated.
My only guess is that you are checking the wrong registry key or the returned path is quoted and/or has parameters so the file exists check fails.
Verify the path with Messagebox mb_ok $R0
before the IfFileExists
line and if it is empty you should try Process Monitor, it might be able to give you some clues...