I am working on an install in NSIS.
This install installs an enhancement to an existing program.
I use InstallDir to set the default install path of this program and then Page directory to let the end user pick another one.
What I want to do is to be able to force the user to only pick an install folder that contains a specific file (which would be used to be sure they only installed in a folder containing an install of the program my enhancement is for)
How can I do this? Preferably I would like to prevent the user from choosing the wrong folder in the first place but if I cant do that, I want to bring up the directory dialog, have the user select a folder, verify that its correct, if its not, go back and bring up the directory dialog again (after displaying a message to the user) and keep going until the user either cancels the installer or they pick a valid folder.
Verifying that the selected install folder exists and contains <file>
4 posts
OnVerifyInstDir
Just add the Function ".onVerifyInstDir" to your script. This function is called everytime the user changes the directory. If you want to ensure that the folder contains a specific file then you could do this with "IfFileExist". Here an example:
BTW: Nearly every software store it´s installdirectory in the registry. So you can read it out and use it as default instdir so the user don´t have to browse to the right folder. You only have to find out the right registry key. And if the key doesn´t exist you can define a "default installdir":
Just add the Function ".onVerifyInstDir" to your script. This function is called everytime the user changes the directory. If you want to ensure that the folder contains a specific file then you could do this with "IfFileExist". Here an example:
have fun 😉Function .onVerifyInstDir
IfFileExists "$INSTDIR\somefile.exe" FileIsThere
Abort ; user can´t go on if "somefile.exe" isn´t present
FileIsThere:
FunctionEnd
BTW: Nearly every software store it´s installdirectory in the registry. So you can read it out and use it as default instdir so the user don´t have to browse to the right folder. You only have to find out the right registry key. And if the key doesn´t exist you can define a "default installdir":
And alltogether with .onVerifyInstDir the user can´t do anything wrong no more. 😉InstallDir "c:\programs\examplesoftware\" ;define default installdir
InstallDirRegKey HKLM "Software\ExampleSoftware" "TheInstallDirRegkey"
;if exist $insdir contains now the path stored in this key
Are you sure you can abort from .onVerifyInstDir? I thought you'd have to use the page's leave function and call abort there...