Archive: installation dir


installation dir
Hi all,

I check in my installation if the product is already installed, and if it is, I consider being a reinstall, so I don't show the choose-dir-page, b/c I use as INSTDIR the already used dir, so where the application is already installed.

This is fine, but still the user could overwrite this by using as cmd line the /D=C:\Program Files\Foo. This is a problem for me b/c imagine the scenario:
- first installation: product gets installed in C:\Program Files\MyApp
- later the user wants to reinstall using a newer version so if he runs the setup with no param, everything fine, as C:\Program Files\MyApp will be used by default, but if the user uses the /D=C:\Program Files\Foo another instance of my app gets installed in a second directory, which I can't allow.

Is there a way to prevent this? Meaning, in case I'm in a reinstall scenario (product already installed), to ignore the cmd line param /D=C:\Program Files\Foo both in silent and no-silent installations?

Thx,
Viv


If the product is already installed (i.e. a registry entry exists) then compare the $INSTDIR with that stored in the registry. If it is not the same, then alert the user.

-Stu


Hi Stu,

If the product is already installed (i.e. a registry entry exists) then compare the $INSTDIR with that stored in the registry.
1) Where should I do that check, so that to be early enough? in .onInit would be ok?


If it is not the same, then alert the user.
2) And how should I behave in a silent install? I think I shouldn't warn the user in that case, but just overwrite the INSTDIR with the value read from registry.
Again, is it early enough to do so in .onInit? (I'm a little confused by the fact that InstallDirRegKey is an instructions that is out of any section or function)

3) So, seems that a cmd line /D=C:\Program Files\Foo overwrites the following 2 instructions:

InstallDir "$PROGRAMFILES\${PRODUCT_COMPANY_LS}"

and

InstallDirRegKey HKLM "Software\${PRODUCT_COMPANY_NAME}" "${PATH_TO_MAIN_APP_REG_KEY}"


I would have expected to overwrite the

InstallDir "$PROGRAMFILES\${PRODUCT_COMPANY_LS}"

only.

Thx,
Viv

kichik, can you pls give me a suggestion to this one too? I'm pretty sure I'm not the first one wanting to preserve in a silent install the INSTDIR from a previous installation, but couldn't find a "recommended" way to go ...

Thx,
Viv


Before the script is executed, including .onInit, $INSTDIR comes from the first option available of these:

  1. From command line (/D=)
  2. InstallDirRegKey
  3. InstallDir
To keep the installation directory for future installations, you'd usually want to use the registry.

Thx kichik, I noticed that. My problem is:

I have in the script the


InstallDir ..
InstallDirRegKey ...


and b/c of the InstallDirRegKey in a reinstall case everything is ok, as the last INSTDIR is used as it is saved into the registry.

But, the user might uses /D= which in a first-install case is ok, but in a reinstall case would actually install 2 instances of my application (as it won't reuse the last INSTDIR) and this is not what I want.

So, is there a way to prevent this? Meaning, in case I'm in a reinstall scenario (product already installed), to ignore the cmd line param /D=C:\Program Files\Foo both in silent and no-silent installations, so that the InstallDirRegKey to be used instead? If yes, _where_ and _how_ can I do that?

Thx,
Viv

If it were me, I'd include a check in .onInit that would check to see whether or not the application was installed and if so, Reassign $INSTDIR to another location using a STRCPY command. If it WASN'T already installed, then just proceed as normal.

(You could also look at using GetOptions and GetParamters to specifiy your own parameters if that's easier. Both of these are in the help manual under Appendix E.)


If it were me, I'd include a check in .onInit that would check to see whether or not the application was installed and if so, Reassign $INSTDIR to another location using a STRCPY command. If it WASN'T already installed, then just proceed as normal.
This is what I was thinking too, but wasn't sure if this is the way to go. and also wasn't sure if it's soon (or later) enough to do this in .onInit.

(You could also look at using GetOptions and GetParamters to specifiy your own parameters if that's easier. Both of these are in the help manual under Appendix E.)
Yes, I already use that for other stuff, but for the INSTDIR I didn't know how to prevent a user, that knows the NSIS cmd line default params, to use the /D= which for my reinstaller would have been a killer.

Thx,
Viv

.onInit is the first thing that gets processed, so adding your code there should be fine.


Thx Comperio, so in the end I did in .onInit:


ReadRegStr $isAlreadyInstalled HKLM "Software\${PRODUCT_COMPANY_NAME}" "${PATH_TO_MAIN_APP_REG_KEY}"
${If} $isAlreadyInstalled == ""
MessageBox MB_ICONEXCLAMATION|MB_OK "Installed"
${Else}
ReadRegStr $INSTDIR HKLM "Software\${PRODUCT_COMPANY_NAME}" "${PATH_TO_MAIN_APP_REG_KEY}"
${EndIf}


Thx,
Viv