Skip to content
⌘ NSIS Forum Archive

$INSTDIR does not initialize in .onInit function at runtime

16 posts

vtsaran#

$INSTDIR does not initialize in .onInit function at runtime

Hello, listers!
I am at a loss.
I have two almost identical scripts. In both of them I initialize $instdir at compile time. Then, in the .onInit I have:

IfFileExists "$INSTDIR\myfiles*.*" Jump_if_Good Jump_If_Bad

but $INSTDIR does not initialize and installer behaves as though the files are not found. If I substitute $INSTDIR with an actual directory, then everything works fine.
The interesting thing is that the function which initializes the $INSTDIR at compile time is exactly the same in both scripts.

Do you have any idea about the possible causes of this misbehavior?

Thanks,
Victor
vtsaran#
Hello, guys!
OK, here goes the script.
Regards,
Vic
Joel#
I find you error:

InstallDir "$INSTDIR"
The above line is wrong, is should:

InstallDir "$PROGRAMFILES\${MUI_PRODUCT}" ;or another you want
vtsaran#
Well, it works in another script. Plus I want my $INSTDIR to be generated at runtime depending on the conclutions drawn from reading appropriate registry keys.
Regards,
Victor
Joel#
$INSTDIR contains the installation directory "variable"
from one of these three:
1. From the registry using the InstallDirRegKey.
2. When you use the InstallDir.
3. When the user use the Browse button the change the Installation path.
vtsaran#
Thank you everybody. I can't believe how unattentive I was. There was a typing error in the line

InstallDirRegKey HKLM "Software\${MUI_PRODUCT}" "Install_Dir"

I accidentally omitted a quote.
So the following reads correct and works fine.

InstallDir "$INSTDIR"
InstallDirRegKey HKLM "Software\${MUI_PRODUCT}" "Install_Dir"

Now my $INSTDIR is defined at run time.

Regards,
Vic
kichik#
Your code is still wrong. The InstallDir sets $INSTDIR if InstallDirRegKey fails. You set something to itself when it's empty. It only works for you because the registry key is there, once it's gone you'll get an empty one instead. If you do want an empty $INSTDIR if the registry key is not there then you just don't need InstallDir.
Joel#
I have this and it works:

InstallDirRegKey HKLM "Software\${MUI_PRODUCT}" "Install_Dir"
InstallDir "C:\path"
This isn´t right: InstallDir "$INSTDIR"
vtsaran#
OK, but then I don't understand something. How would I change $INSTDIR at run time? A very basic scenario: my installation directory will change depending on the version of another application installed. If I declare some path for InstallDir, then I have to stick with it. That's not what I want.
My current scenario works because if there is no InstallRegKey for my application, then I assume it was never installed on this computer, otherwise, I check for existence of certain files.

Regards,
Vic
vtsaran#
Hello,
Kichik, you were right, I grant. I took out the line

InstallDir "$INSTDIR"

and it still works the same. I think I understand my mistake now.
Thanks everybody.

Regards,
Vic
kichik#
Just to make sure everybody understand, this is how it works:
  • Installer starts
  • The value specified using InstallDir is copied to $INSTDIR
  • The value specified using InstallDirRegKey (if found) is copied to $INSTDIR
  • .onInit is called, and later everything else


You can change $INSTDIR wherever you want in the script with worrying about InstallDir and InstallDirRegKey. Those just give the initial values.