Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Environment Variables
By David Roossien
david.roossien@sbcglobal.net
updated 4/2010
Thats quite a title, but this tutorial explains how to use all of these. I hope it helps you create an
installer that works for you.
The task:
Create a Basic MSI installer using InstallShield 2010 (or 12) that reads a Windows Environment Variable
to determine where to install some files. This sounds like a simple task, but it sure helps to have a 16
page example.
The approach:
Create a Directory Property that we can tie to the Destination computers folder in Application Data-
>Files and Folders.
We will use InstallScript to get the value of an environment variable from the Destination computer.
During installation we will change the value of the Directory Property using InstallScript. When we
change the value of the Directory Property the Destination for that folder will change dynamically during
runtime.
2. In InstallShield 2010 (or 12). Create a new Basic MSI project. I called mine test and put it in
c:\test\test.
5. Go to Organization->Setup Design.
6. Right click on Setup Design and click New Feature. Call it FilesFeature. I called mine
FilesFeature because all this simple installer does is copy files onto the target machine.
c. You can verify that a Directory Property was created by going to Behavior and Logic-
>Property Manager. You should see {DIRPROPERTY1}{temp}
9. Go to Behavior and Logic->Property Manager. Locate DIRPROPERTY1 and change its value to
the folder c:\test. This will now be the default Destination folder for FilesFeature.
Figure 3 Property Manager with Directory Property
11. Go back to Setup Design. You should see that {temp} has been replaced with the value c:\test.
Figure 4 Setup Design with Destination changed
13. Right click on Destination Computer under Destination computers folders. Select Launch
Component Wizard.
14. Click Next. For Destination, select the Directory Property you created before.
Figure 5 Launch Component Wizard: Destination
15. Next. Click Add Files. Navigate to c:\test\test\test.txt. Open.
16. Next.
Figure 7 Launch Component Wizard: Finish
17. Finish.
18. Now you should see a folder called c:\test with an AllOtherFiles component. Test.txt should
be listed with that component.
Figure 8 Files and Folders
19. If you return to Organization->Setup Design you should see AllOtherFiles listed below the
FilesFeature we created earlier.
Figure 9 Launch Component Wizard: Files
21. Now, we are close to adding our InstallScript, but first we still should go down to Media-
>Releases and make a New Product Configuration. For this example, we will create a product
configuration that builds a single compressed setup.exe. Our file, test.txt, will be compressed
inside the setup.exe.
22. Go to Media->Releases. Right click on Releases and select New Product Configuration. Accept
Product Configuration 1 as the name.
23. Right click on Product Configuration 1 and select New Release. Accept Release 1 as the
name.
24. Click on Release 1. On the Build tab, under Compression, select Compressed.
Before continuing onto programming the InstallScript we will assume that the Destination computer will
have a Windows System environment variable called test. Its value will be c:\test or any other folder
you wish to designate.
1. Go to Behavior and Logic. Right click on Files below InstallScript. Select New Script Files.
This will create setup.rul below Files and MyFunction below Functions.
2. Below Functions, click on MyFunction. This will open setup.rul in the editor.
///////////////////////////////////////////////////////////////////////////////
// Function: setInstallFolder
//
//
///////////////////////////////////////////////////////////////////////////////
function setInstallFolder(hMSI)
NUMBER nvSize, nReturnValue;
begin
MessageBox ("Environment variable " + ENV_VAR + " not found. Please create it and set its
value before running this setup program..", SEVERE);
else
// concatenate the value of the env variable and sub folder. This will be the Destination
endif;
endif;
end;
5. Go to Behavior and Logic->Custom Actions and Sequences. Right click on Custom Actions.
Select Custom Action Wizard. Next. For Name, give it setInstallFolder.
8. Next. Next. Next. On the Insert Into Sequence dialog, under Install Execute Sequence,
select After InstallInitialize (we will change this in a minute). Next. Finish.
9. Select the setInstallFolder Custom Action you just made and make the following changes:
13. I like to use a virtual machine for testing installations. This allows me to safely install and
use Add/Remove Programs to uninstall the application.
Conclusion
I hope this example helps you get started with InstallShield, InstallScript, properties and environment
variables. Let me know if it does!