How Software Works

The Inner Workings Of Programs

First Published: PC Today
Date Published: March 2004
By Kevin Savetz
When you install a new application on your PC, a lot goes on behind the scenes that most of us take for granted. Running that installation program launches a complex series of events that leads, ultimately, to making the new application ready to use. Later, when you uninstall that application, an equally mysterious procedure takes place.

Things were easier in the early days of personal computers, when just one program could run at a time. Today, though, it's not uncommon for a user to have five or more applications running at once, plus innumerable operating system processes that keep the whole show running. When creating software, programmers devote a lot of energy to make sure their program plays nicely with all of those other applications.

We asked three leading software publishers to explain what goes on when you install a new program and uninstall an old one. We spoke with Eric Wong, build engineer at InterVideo (www.intervideo.com), which publishes WinDVD movie playing software; Alex Huang, an engineer at Ulead (www.ulead.com), which publishes VideoStudio video-editing software; and J. Cornelius at CoffeeCup Software (www.coffeecup.com), which publishes CoffeeCup HTML Editor. For all three programs, the basic process is the same, but no two programs are exactly alike: Each has its own special features and considerations.

Add New Software

The installer is software whose job it is to put a program's components where they belong. If you're installing a program that you downloaded from the Internet, you simply double-click the installer and it goes to work. If it's a commercial program on CD-ROM, chances are the installer will run automatically when you insert the disc. A special script on the CD called Autorun.inf tells Windows which program to run when you insert the disc.

If you've installed a few programs in your computing career, you know the basic process from there. Although the exact procedure can differ from one program to another, typically you'll be shown a license agreement and perhaps a Read Me file and asked in which directory to store the program's files. You'll also be asked which program group the icons should belong to. The installer works for a while and asks if you want to run the program right away.

You've probably noticed that many installers look very much alike. This is because programmers usually use an installer builder, which is a specialized utility that does most of the work of creating the installer application. The installer builder provides the infrastructure for loading software onto a computer. There are only a handful of these utilities, so after you've installed a few programs, you will start to notice similarities in the installation process of applications, even ones from different companies.

So you've downloaded the program or inserted the CD-ROM into your optical drive. The program is ready to be installed on your PC. Let's look at what happens next.

Run The Installer

When you run Setup.exe, the installer first unpacks itself, decompressing the files it contains into a temporary directory. The installer then shows you the license agreement and asks you to accept it, and then asks where it should store the program's directory on your hard drive. By convention, installers on Windows XP will default to storing applications in the Program Files directory to keep them stored in a handy place.

Now the installer can copy the program's files to the directory that you chose. A single application is usually made up of many individual files. Most of them (the ones that are specific to that application) are stored in the application's directory, but some must be stored elsewhere.

Share and share alike. Some files are shared-that is, they are available to every program on that system, not just the one you are installing. A shared file might include a CD-ROM driver (you want to be able to access the drive from every program) or software for displaying QuickTime video.

One common type of shared file is DLL (dynamic-link library; a file that contains a collection of related functions that any application can access). Shared files are stored in a directory that's available to other software within the WINDOWS folder.

Depending on the application, the installer may have to add many shared files. Ulead VideoStudio, for example, installs the DirectX graphics library, Windows Media library, and QuickTime support.

If the installer added any shared files, it needs to tell the other software on the PC that a new shared resource has been installed. Some installers do this the nice way, politely telling the other software what has changed on the PC. Many other installers do it the relatively easy way, by making you reboot the PC before you can use the software. When Windows restarts, it makes the new shared software available across the system.

Although you've barely begun using the program, the installer is already taking notes in case you decide you don't want to use it after all. As it stores each file in its new home, the installer makes notes about what it has done in a log file. If you decide to uninstall the program later, the log file will tell the uninstaller application which files to remove and which folders to delete.

The Registry

The system Registry is a vital part of Windows that every application interacts with. The Registry is a database in which Windows stores settings and preferences for software and hardware. Information from your Control Panel settings (for instance, your screen resolution and system volume) are stored there. Your applications also store settings information in the Registry.

"Changing the Registry database takes most of the time, probably 99% of the installation time," Alex Huang, engineer at Ulead, says.

The software installer must update the system Registry to tell it about any shared files it has added and set default settings for the application you are installing. In WinDVD, for example, the Registry stores the user's speaker settings, audio preferences, and video effects mode settings. "Anything that makes the program behave the way you want it to" goes there, Huang says. The first time you run the application, the default setting will be there. When you change a setting within a program, it is saved to the Registry.

Have you ever wondered how a program modifies menus in Windows itself? CoffeeCup HTML Editor does it, using something called Registry association. When you right-click an HTML file, a new contextual menu option appears: Edit In CoffeeCup HTML Editor. This makes it simple to open an HTML file in the editor.

The need to update the Registry is the main reason that many software installers will warn you to quit other programs before you begin to install the software: The installer wants to be sure that no other programs will be working with the Registry at the same time.

You can use the Registry Editor, which is built into Windows, to change the behavior of your software, sometimes in ways that aren't available in the preference controls. A guide to fine-tuning your system with Registry editing is available online at www.winguides.com/registry. Beware: Incorrect changes to the Registry can seriously mess up Windows and your applications, so be sure to know what you're doing before you modify it.

Final Steps

Having finished the hard work of putting the files in the proper places and checking in with the system Registry, the installer has some final tasks to do. Many installers will add a shortcut to the application to your Desktop or Start menu. It erases the temporary files that it created and adds icons to the appropriate Windows program group. Finally, you'll see a message that the program has been installed. Your new software is ready to use.

Uninstall

Some time later, you may want to remove a program from your PC. You simply need to uninstall it. Although some programs have an uninstall icon in their application directory, in WinXP the proper way to remove an application is using the Add Or Remove Programs control panel. "Microsoft has discouraged developers from putting an uninstall icon in with their program. They want users to use the [Add Or Remove Programs] control panel. Regardless of where it is, they both point to the same place," Wong says.

"The Windows Add/Remove programs applet does nothing more than execute the programÔs specified uninstaller," Cornelius of CoffeeCup Software says.

The uninstaller application is actually the same program that installed the program in the first place. "The installer needs to put a copy of itself onto the machine, so the Setup.exe can run again when you uninstall," Wong says. Otherwise, you would have to insert the CD to remove the program. Referring to the log file that was created when the program was installed, the uninstaller removes the files and folders that it created and removes relevant entries in the system registry. The log file is like a trail of breadcrumbs, so the system can find its way back to where it started.

Do some extra housekeeping. The uninstall process might not remove everything related to an application. Although this can be frustrating for users wondering why extraneous files for programs they don't use anymore are left littering the PC, the uninstaller usually has a good reason for leaving them behind.

First, the uninstaller will only delete files that the installer put there in the first place. If there's anything else in that directory (files that you saved, for instance), a well-behaved uninstaller will leave those files alone, as well as the directory that contains them.

According to Cornelius, CoffeeCup HTML Editor's uninstaller, like most uninstallers, "won't delete a folder if there are files in it that the installer didn't install. This is to protect any files you may have created." For that reason, it is a good idea to save your work to your My Documents folder instead of the folder that contains the application or anywhere in the Program Files directory.

In addition, the uninstaller needs to make hard choices when dealing with shared files. If the uninstaller removes a shared file, other programs will fail. If an uninstaller believes that the program it is removing is the only one that uses a particular shared file, it will usually ask for confirmation from you: Should it delete Somefile.dll? Answering no is the safer option, but it is likely to leave lingering detritus that no software really needs. Answering yes could break some other software, but those chances are low. The system Registry has a good handle on what software utilizes which shared files.

And if all else fails . . . Not every uninstaller does a perfect job every time, and some software doesn't even include an uninstaller.

If the installer replaced a shared file with a newer version, another problem can arise when uninstalling the program: Do you want to downgrade that shared file to the original version or maintain the more recent version? A well-behaved installer will save any files that it replaces with a newer version. "When you uninstall VideoStudio, the user has the choice of keeping the latest shared files or recovering the older files," claims Huang.

Which option should you choose? In most cases, it's a good idea to stick with the newer version of the shared file-other software may rely on the features of the later version. On the other hand, if you're uninstalling new software because you suspect it made your system unstable, go ahead and roll back the shared file. After all, it could be part of the problem.

The Inner Workings

There you have it: a glimpse into the complicated dance that occurs inside your computer every time you install or remove software. The next time you install an application, you'll look at the process in a new light.

Reprinted with permission from PC Today magazine.


Articles by Kevin Savetz