Who Knew Setup Could Be This Fun (or Easy)?

Brian Hart

Late last year Microsoft released the Windows 2000 Readiness Kit. Registered owners of Visual C++ can download a copy from the Microsoft Web site. It also comes free with new copies of Visual C++. Brian Hart looks at the much-awaited Visual Studio Installer and walks you through creating a setup for an application. He also discusses design issues for Setup programs.

In the September 1999 issue of Visual C++ Developer, I wrote a program called IAD that makes a dialup connection to the Internet. IAD uses the WinInet API to initiate and terminate Dial-Up Networking connections for the user using the Internet Explorer interface. This gives the user as consistent a computer-using experience as possible. In this article, I’ll use the Visual Studio Installer to make an installation program for this sample, so it can be easily employed by users as well as developers.

The first step is to install Visual Studio Installer. The place from which you run the installation for that isn’t obvious, so I’ll save you some time hunting for it. Microsoft put so much information on the Windows 2000 Readiness Kit CD that it took a little time to find. When you put the "Disc 1" Windows 2000 Readiness Kit CD into your CD-ROM drive, you’ll first get a screen that contains information about the various parts of the Plus Pack. You’ll want to click the "Windows 2000 Readiness Kit" icon on the left, scroll down, and then click "Launch the Windows 2000 Readiness Kit." Next, simply click the blue underlined Visual Studio Installer link on the right, and then click Install Visual Studio Installer.

The Setup process for the Visual Studio Installer is straightforward. Once it’s installed, you can run it from the Start menu, and the IDE for the Installer is the Microsoft Development Environment (not to be confused with the Visual C++ IDE). The New Project dialog box appears, as shown in Figure 1.

You can select three different types of Installers:

• An Empty Installer starts a new project, which will eventually become a Setup program

• A Merge Module is a fancy name for a patch, which you can use to distribute application updates to users

• A Visual Basic Installer makes a Setup program from the output of a Visual Basic project

The Merge Module is a pseudo-installer that stores shared code and installation files that can be used and installed by more than one installer created with the VSI. Typically, these install files are frequently needed by a large number of programs, such as redistributeable files. These include the MFC DLLs, the VB Runtime Libraries, and the ATL code, to name a few. Microsoft recommends use of merge modules to install files, because this helps Windows keep an accurate reference count of which shared files on a user’s system can be uninstalled and which need to remain.

I won’t really be dealing with Visual Basic Installers here, as they’re beyond the scope of this publication. They work just like installers (another name for a Setup program) made for Visual C++ programs, so I’ll focus on the first project type for now.

Using the New Project dialog box, create a new, empty installer. For demonstration purposes, I’ll use the Visual Studio Installer for my IAD sample program. The New Project dialog box suggests a subdirectory into which you can put the files for the new installer. Usually the convention, as with any programming project, is to name the project subdirectory after the project. However, I’m going to break from convention at this point and simply make the installer directory a subdirectory called \Setup of my InternetAutoDial project directory, and give the installer project the name of IADSetup.

When the project is created, the Project Explorer in the Microsoft Development Environment shows us the project (see Figure 2).

The project is called a Solution and can have more than one project contained in it. This is convenient for grouping installer projects and merge module projects together so you can keep track of what goes with what. The icons in the Target Machine folder illustrate the various aspects of the installation.

You start with what the installation will do. I’m going to install the IAD sample as if it were software purchased from a store: The user can’t have the source code, and there’s no Help file or INI file, so this installation will be relatively simple. I’ll simply prompt the user for the folder they want to install IAD into, and then install the InternetAutoDial.exe file into that folder.

It seems obvious, but one of the most important steps in creating any installation program is to specify the files to be installed, and where they’re to be installed. This is simple for our application. Under the Target Machine folder in the Project Explorer, double-click the File System icon. In the window that appears, there are two columns. The column on the left contains a list of the folders into which files can be installed, and the column on the other side lists the files you’ve added for installation.

The folder column also contains a list of the special Windows folders on the user’s machine, such as the Program Files folder, the Start menu folder, the folder for the Desktop, and so on. You can add folders, files, and shortcuts to the file system by right-clicking the File System on Target Machine icon at the root. For my purposes, since the EXE file of the IAD sample is self-sufficient (no help files, no DLLs, no nothin’), just go ahead and add the EXE file to the installation. All that this requires is to add the InternetAutoDial.exe file to the Application Folder.

But you’re not done with the files yet. How about placing a shortcut on the Desktop to let the user easily access the program? No problem. Right-click the InternetAutoDial.exe file, which you just placed in the Application Folder folder, and select Create Shortcut. This creates a shortcut to run the file, which I renamed "Internet AutoDial." Drag this shortcut to the User’s Desktop folder, and the shortcut will now be placed on the Desktop by the installer.

Next, add an icon for the user’s Start menu. I first created a folder on the User’s Start Menu folder called Programs, and then another folder under that called InternetAutoDial. The "User’s Start Menu Folder" means the folder for the whole Start menu, not just the Programs folder. If I put the Internet AutoDial folder under User’s Start Menu, it would be on the same level of the Start menu as Programs. I went back to the InternetAutoDial.exe file and created another shortcut, then dragged it to the User’s Start Menu folder to make the installer place an icon for Internet AutoDial under the user’s Start menu.

The User Interface icon controls the user interface dialog boxes that the user sees as the Setup Wizard. This guides the user through the installation process, and it also guides the user through the un-installation and repair process, which the user can invoke from the Add/Remove Programs dialog box. The user interface settings are sufficient; they welcome the user, prompt for a destination directory, confirm the installation choices, display installation progress, and notify the user when installation is complete. You can add and remove dialog boxes and change the user interface; I’ll discuss how in a future article. For many projects, including my auto-dialer, the default user interface is fine.

With these basic steps completed, make a few changes to the Installation Properties to make sure the installer works properly. Select the IADSetup Properties item from the Project menu, and then select the All Configurations choice in the drop-down list at the top of the Properties dialog box that’s displayed. On the General tab, select the Build Type as Installer with Windows Installer Loader. This ensures that even if the user hasn’t installed the Windows Installer software or doesn’t have Windows 2000 installed, the installation will still work. I also selected Optimize for Size in the Compression drop-down because I wanted the download time to be as short as possible. The other tab on which I made changes was the Product Information tab. I changed the name from the name of my project, IADSetup, to Internet AutoDial. This is an important change to make because this is the name that displays in the Wizard dialog boxes all over the installer’s user interface.

Included in the IADSetup.zip file available from the Subscriber Downloads at www.pinpub.com/vcd are the same files I distributed with the September 1999 article, plus the project and output files for the installer in a \Setup subdirectory of the main InternetAutoDial project directory. To use the installer and take it for a test, go into the \Setup\Output\Disk_1 directory and double-click the Setup.exe file. This will search your system for the Windows Installer software, and if it’s not present, will install the software. Setup will then launch the installer created in this article.

And voila! There you have an introduction to the basics of software installation, and you can see how exceedingly easy the process is for both user and developer. What’s more, Microsoft hands you this power for free–it used to be that developers who wanted to make setup programs were at the mercy of proprietary software vendors’ installation technologies in order to produce software installations (at least this developer was, and it becomes a drain on the pocketbook). And even then a lot of work had to be put into making a usable setup program with an intuitive interface.

With the Visual Studio Installer, Microsoft makes things quicker and easier for both the developer and the user. The user interface is so simple even your parents can use it, as well as your children and people who haven’t so much as touched a computer in their lives. In addition, the user interface also looks professional and consistent with the rest of the Windows interface, so it makes a good impression. In upcoming articles, I’ll explore the Visual Studio Installer in further detail and discuss how to harness its power.

Download IADSetup.zip

Brian is a full-time, second-year physics and mathematics double-major and music minor at Hamline University, located in Saint Paul, MN. bhart@piper.hamline.edu, http://www.hamline.edu/~bhart/ http://www.wndbsoft.com/ .