For some projects I occasionally find that it is necessary to prompt the user for a destination location in addition to the default INSTALLDIR.
For example, what if I want to confirm the Java JRE directory that I found installed is the one the user wants to associate with their applications (quite possible they certified an older JRE version – not the most current). The only reference I found on how to do this was for InstallScript MSI project, but I am working solely in Basic MSI projects.
In order to provide the end user with the same Browse to a folder dialog used in a default installation, the following steps can be followed for use in a Basic MSI InstallShield project:
Create a new Directory that will be used to hold the JRE directory found – and will be displayed in the Browse directory. Since I have never, (repeat never) mastered the Directory Table (using Direct Editor), here is how I approach it. I create a new component (delete if afterwards) and select the dropdown to create a new directory entry.
Now a directory browse dialog is presented:
Using the INSERT key, create a new directory “JRE Path”
Now rename the Directory Identifier to be all CAPS, such as “JRE_PATH” – this will be the MSI Property that we will use as our Directory. Now we need to create some dialog screens to display and allow the user to browse to a new directory.
Go to the Dialogs section, and export a dialog that we will need to “repurpose” for our needs. For our example, we are going to export the dialog “AdminChangeFolder” by selecting the dialog and right-clicking. Export the dialog ISD to a folder you can retrieve it from later.
Now rename the original “AdminChangeFolder” to “AdminChangeFolder_ORIG” to preserve it. I do this because even though I tried to rename the dialog during export, it always appears with the same name – overwriting the original.
Now import back the “AdminChangeFolder” dialog by right-clicking on the “All Dialogs” title. The repository appears:
Browse to the saved dialog, and select it – it will appear in the repository as shown here:
Select OK and the dialog will appear back in your listing of dialogs.
WARNING: if this popup dialog appears:
You must select the red conflict item and select “Overwrite”, like this:
What is happening is that the internal bitmaps are being exported as “NewBinary1” files and stored in the same directory as the project ISM file (Hint: look for a file “NewBinary1” and copy as “NewBinary.jpg” and you will see the banner bitmap). Here is the result you might find – the banner bitmap points to a file “NewBinary1” – not to the original file location:
The solution is to replace the “File Name” with the original value, such as: <ISProductFolder>\Redist\Language Independent\OS Independent\IsDialogBanner.ibd (With InstallShield v10.5 it will ripple this NewBinary1 reference to ALL of your dialogs, so you may have to create a new InstallShield project to determine the original file values. If this happens, then you either must go to each dialog and correct it, or you can open the Direct Editor, go to the “Binary” table and alter the displayed value for NewBinary1,
Now rename “AdminChangeFolder_ORIG” to “JavaChangeFolder”.
We are going to leave this dialog and create a new dialog “JavaDirectory” that will display the Java JRE directory along with a “Change” button.
Here is a sample of one I created:
Essentially it contains a text box, a PathEdit box and a Change pushbutton. The property associated with the PathEdit box is “JRE_PATH”.
We want the user to see a directory browse button when they hit the ‘Change’ pushbutton, so we need to switch to the ‘Behavior’ to edit the JavaDirectory dialog behavior. On the Change pushbutton (titled ‘PushButton1’ add an Event “SpawnDialog” with the argument “JavaChangeFolder” and a condition of 1 – as shown here:
Now change to the dialog “JavaChangeFolder” and in the dialog view, change ALL of the property values from “TARGETDIR” to the property “JRE_PATH” as shown:
Then you will need to switch to the ‘Behavior’ view and alter the event OK and change the argument from “TARGETDIR” to “JRE_PATH”
FINALLY – go to the project Property Manager section and delete the property “JRE_PATH” – if you don’t the path will be incorrectly set as “0” and your project will hang during the starting and fail with error 1603!! For some reason, this value will keep appearing during your development, so you may need to double check it a couple of times.
Now, to prime the directory “JRE_PATH” you can setup an Custom Action to grab the environment variable JAVA_HOME and prime the directory with this value, or you can execute a Custom Action InstallScript that will evaluate the machine and set this MSI Property (MsiSetProperty xxx) to a directory value. Here is a sample display of the dialogs when running:
Hope this helps!