Archive: Detect one of several possible installs


Detect one of several possible installs
Just come back to NSIS for a specific project after a long break and I've forgotten all I ever new. And as usual the powers want it ASAP - so I shall consult the knowledgeable!

I want to detect an existing installation (created with another installer) and present that as the default installation directory (for adding files to a product). The path can be found in the registry, but is complicated by the fact it could be one of four applications, so I want to try each in turn and use the first one found.

I have written this (key names are merely indicative!):


InstallDir "$PROGRAMFILES\DefaultDir"
Var /GLOBAL COMPARE
StrCpy $COMPARE $INSTDIR
InstallDirRegKey HKLM "SOFTWARE\CompanyName\Product 1" "Application Path"
StrCmp $COMPARE $INSTDIR 0 found:
InstallDirRegKey HKLM "SOFTWARE\CompanyName\Product 2" "Application Path"
StrCmp $COMPARE $INSTDIR 0 found:
InstallDirRegKey HKLM "SOFTWARE\CompanyName\Product 3" "Application Path"
StrCmp $COMPARE $INSTDIR 0 found:
InstallDirRegKey HKLM "SOFTWARE\CompanyName\Product 4" "Application Path"
:found

However this cannot work because you can't have StrCmp outside a function and you cant use InstallDirRegKey inside a function...

Any hints (or slaps for writing drivel code!) are welcome. Thanks.

Use ReadRegStr within the function

ClearErrors
ReadRegStr $0 HKLM "SOFTWARE\CompanyName\Product 1" "Application Path"
IfErrors 0 found


Excellent - many thanks!