As a shortcut for developing setup and uninstall programs, the Professional and Enterprise Editions of Visual C++ include the SDK edition of Stirling Software's InstallShield. (The Learning and Standard Editions don't include this tool, but you can purchase it separately. If you don't have access to this tool, you can still benefit from reading the information in this lesson.)
This lesson introduces the InstallShield toolkit, which enables you to write a script that specifies the steps you want performed during installation. InstallShield then builds a Setup program that installs your product on a user's computer.
With InstallShield, you don't have to write a separate script for uninstallation. InstallShield creates an uninstall program named Uninst that reads a log file created during the setup process. The log file enables Uninst to reverse the steps performed during setup.
InstallShield creates a Setup program for your project that looks and acts much like the Setup program you used to install Visual C++. Microsoft creates Setup programs for many of its products using InstallShield.
An exhaustive description of InstallShield is beyond the scope of this lesson, which is intended only as an introduction to the product. Setup programs today can be surprisingly sophisticated, capable of handling a wide variety of file types, accommodating different operating systems, and handling a bewildering number of potential problems. They must work not only with traditional distribution media such as disks and CD-ROMs, but also across networks and the Internet. InstallShield is not difficult to use, but it offers such a wide array of options designed to address installation issues that gaining familiarity with it can take a while. Furthermore, complete control over the product requires learning its scripting language, InstallScript. As with most programs, practice is the only true teacher.
InstallShield treats your Setup program as a project, the same term applied to normal Visual C++ projects. To avoid confusion, this lesson employs the phrases Setup project or installation project when referring to work done inside InstallShield, and application project when referring to the Visual C++ files that the Setup program deploys in their compressed state.
After this lesson, you will be able to:Estimated lesson time: 15 minutes
- Configure InstallShield to run as a Visual C++ tool.
- Step through the InstallShield tutorial.
- Create a simple Setup program using InstallShield.
If you selected InstallShield when installing Visual C++, the Visual C++ Tools menu already contains a command for starting the InstallShield Wizard. However, if the command does not appear in the Visual C++ Tools menu and you are not using the Learning or Standard Edition of Visual C++, you should install InstallShield now.
The Setup program installs InstallShield, places a command on the Start\ Programs menu, and adds the InstallShield Wizard command to the Visual C++ Tools menu.
The InstallShield program provides a good tutorial that demonstrates how to develop a sample Setup program for the familiar Notepad utility. The tutorial walks you through various steps, eventually creating a Setup program that places an icon and command on the Programs menu. When selected, the command invokes Notepad.
The tutorial shows how InstallShield categorizes your application files into different groups, allowing you to work on different parts of an installation project. Each group contains files with similar characteristics, such as system DLLs, executable files, and Help files.
After running the completed Setup demonstration, be sure to uninstall it by running the Add/Remove Programs applet, as suggested in the tutorial's last step.
The preceding example shows how to start InstallShield from the Programs menu, activating the Project Wizard to create a new project or to open an existing project. You can also run InstallShield from inside Visual C++ by clicking the InstallShield Wizard command on the Tools menu. This alternative is convenient for creating a Setup program for an existing Visual C++ application project, because it fills in information that you would otherwise have to enter manually. When you click the InstallShield Wizard command, the wizard appears as shown in Figure 14.3. Select the desired Visual C++ project, click Next, and follow the wizard's remaining instructions.
Figure 14.3 The InstallShield Wizard, invoked from the Visual C++ Tools menu
InstallShield scans the application folder and locates all necessary executable files, adding them to the installation project. Figure 14.4 shows how the wizard lists the application's dependency files. In this case, the demo.exe application links dynamically to MFC, so InstallShield adds MFC42.DLL to the Setup project. Because MFC42.DLL in turn uses the C run-time library, the MSVCRT.DLL module is also added to the installation project.
Figure 14.4 Listing an application's dependency files in the InstallShield Wizard
If you intend to distribute your application only to sites where you know the files already exist, you might not want to include dependencies such as MFC42.DLL and MSVCRT.DLL in your Setup program. The InstallShield Wizard does not allow you to alter the list, but you can remove the files from the installation project later. After the wizard finishes, it starts InstallShield automatically.
After your installation project compiles and runs correctly, the last step is to build the project. This step enables you to create the Setup.exe program and the associated .cab files to distribute to your users. InstallShield provides the Media Build Wizard to walk you through the steps of creating the Setup program. The following list assumes you have created an installation project and are ready to build a Setup program for it.
You now have a folder named Disk Images in your chosen installation project folder. The Disk Images folder contains at least one nested folder named Disk1, which holds the disk image for the first disk of the series. If the Setup requires additional disks, their images are contained in folders Disk2, Disk3, and so forth. The contents of each Disk folder must be copied to disks or other media of the type selected in the Media Build Wizard's second step. If the installation creates more than one Disk folder, each receiving medium must be labeled with the disk number to ensure that users can insert disks in the correct order when prompted to do so.
As a final test before shipping your application, run the Setup package on a machine other than your development computer. Test the installed application to ensure that all components have been correctly copied and registered, then uninstall the application to ensure that it is correctly removed.
This lesson introduced the InstallShield program, a tool that creates sophisticated installation programs for Visual C++ projects. InstallShield largely automates the entire process of building a Setup program by scanning for dependencies, generating cabinet files, and creating disk images. InstallShield even provides an uninstaller program named Uninst.
Through the Media Build Wizard, InstallShield is accessible from inside the Visual C++ environment where it automatically reads information for the cur-rent application project. InstallShield encourages the sorting of project files into distinct categories referred to as file groups, allowing you to specify different characteristics for each group. InstallShield generates a script that governs the installation process, using its own InstallScript language. Complete control over installation is possible by editing the script.