100% found this document useful (3 votes)
45 views

The Definitive Guide to Windows Installer 1st Edition Phil Wilson (Auth.) pdf download

The document is a comprehensive guide to Windows Installer, authored by Phil Wilson, covering various aspects of installation processes, tools, and best practices. It includes chapters on building MSI files, handling COM components, installation design, and troubleshooting. The guide serves as a resource for developers looking to understand and utilize Windows Installer effectively.

Uploaded by

josmatuli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
45 views

The Definitive Guide to Windows Installer 1st Edition Phil Wilson (Auth.) pdf download

The document is a comprehensive guide to Windows Installer, authored by Phil Wilson, covering various aspects of installation processes, tools, and best practices. It includes chapters on building MSI files, handling COM components, installation design, and troubleshooting. The guide serves as a resource for developers looking to understand and utilize Windows Installer effectively.

Uploaded by

josmatuli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 83

The Definitive Guide to Windows Installer 1st

Edition Phil Wilson (Auth.) pdf download

https://ebookgate.com/product/the-definitive-guide-to-windows-
installer-1st-edition-phil-wilson-auth/

Get Instant Ebook Downloads – Browse at https://ebookgate.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

WiX 3 6 A Developer s Guide to Windows Installer XML 2nd


Edition Nick Ramirez

https://ebookgate.com/product/wix-3-6-a-developer-s-guide-to-windows-
installer-xml-2nd-edition-nick-ramirez/

ebookgate.com

AppleScript The Definitive Guide Definitive Guides 1st


Edition Matt Neuburg

https://ebookgate.com/product/applescript-the-definitive-guide-
definitive-guides-1st-edition-matt-neuburg/

ebookgate.com

The Definitive Guide to HTML5 Video 1st Edition Silvia


Pfeiffer

https://ebookgate.com/product/the-definitive-guide-to-html5-video-1st-
edition-silvia-pfeiffer/

ebookgate.com

The Definitive Guide to the ARM Cortex M3 Joseph Yiu

https://ebookgate.com/product/the-definitive-guide-to-the-arm-
cortex-m3-joseph-yiu/

ebookgate.com
Closure The Definitive Guide 1st Edition Michael Bolin

https://ebookgate.com/product/closure-the-definitive-guide-1st-
edition-michael-bolin/

ebookgate.com

Hadoop the definitive guide 1st Edition Tom White

https://ebookgate.com/product/hadoop-the-definitive-guide-1st-edition-
tom-white/

ebookgate.com

Cassandra The Definitive Guide 1st Edition Eben Hewitt

https://ebookgate.com/product/cassandra-the-definitive-guide-1st-
edition-eben-hewitt/

ebookgate.com

The Definitive Guide to Symfony 1st Edition François


Zaninotto And Fabien Potencier

https://ebookgate.com/product/the-definitive-guide-to-symfony-1st-
edition-francois-zaninotto-and-fabien-potencier/

ebookgate.com

DirectX 9 Graphics The Definitive Guide to Direct 3D 1st


Edition Alan Thorn

https://ebookgate.com/product/directx-9-graphics-the-definitive-guide-
to-direct-3d-1st-edition-alan-thorn/

ebookgate.com
The Definitive Guide
to
Windows Installer
PHIL WILSON

APress Media, LLC


The Definitive Guide to Windows Installer
Copyright © 2004 by Phil Wilson

All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying. recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.

ISBN 978-1-59059-297-7 ISBN 978-1-4302-0676-7 (eBook)


DOI 10.1007/978-1-4302-0676-7

Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.
Lead Editor: Dan Appleman
Technical Reviewers: Chris Gouge, Carolyn Napier
Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis,
Iason Gilmore, Ionathan Hassell, Chris Mills, Dominic Shakeshaft, Iim Sumser
Project Manager: Tracy Brown Collins
Copy Manager: Nicole LeClerc
Copy Editor: Susannah Pfalzer
Production Manager: Kari Brooks
Compositor: Vijay Nicole Imprints
Proofreader: Uz Welch
Indexer: Carol Burbo
Cover Designer: Kurt Krames
Manufacturing Manager: Tom Debolski
Distributed to the book trade in the United States by Springer-Verlag New York, Inc., 233 Spring
Street, 6th Floor, New York, NY 10013 and outside the United States by Springer-Verlag GmbH &
Co. KG, Tiergartenstr. 17,69112 Heidelberg, Germany.
In the United States: phone 1-800-SPRINGER, e-mail [email protected]. or visit
http://www.springer-ny.com. Outside the United States: fax +496221345229, e-mail
[email protected], or visit http://www.springer.de.
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219,
Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit
http://www.apress.com.
The information in this book is distributed on an "as is" basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
The source code for this book is available to readers at http://www.apress.comin the
Downloads section.
Contents at a Glance
About the Author ................................................. .xiii
Acknowledgements .................................................. .xv
Introduction .................................................... .xvii

Chapter 1 Installations Past, Present, and Future ........... 1


Chapter 2 Building an MSI File: Visual Studio and Orca ....13
Chapter 3 COM in the Windows Installer World ...............31
Chapter 4 Searches and Conditions ........................... .49
Chapter 5 Sequences of Events and Custom Actions ... ........ 67
Chapter 6 How Do You Fix It? ................................ 111
Chapter 7 ASP.NET Setups ..................................... 129
Chapter 8 Installing .NET Assemblies ....................... 141
Chapter 9 Installation Design ................................ 169
Chapter 10 Windows Services ................................... 185
Chapter 11 The GAC and Updating Assemblies ..................201
Chapter 12 Updates Using Patches .............................213
Chapter 13 Installation Environments ........................ .227
Chapter 14 How- Tos, Tips, and Gotchas .......................241
Chapter 15 Exploring the Installer APIs .....................265
Chapter 16 Tools and Futures ..................................277

Index ..............................................................283

iii
Contents
About the Author ................................................. .xiii
Acknowledgements .................................................. .xv
Introduction .................................................... .xvii

Chapter 1 Installations Past, Present, and Future ... 1


Background . .......................................................... 1
Where the Files Go .................................................. 1
Redistributing Supporting Files .......................................2
Installing Windows Services ......................................... .2
Files in Use ........................................................ 2
Security and the Target User ......................................... 3
Maintaining the Product ............................................. 3
Environments ...................................................... 3
The One-Way Nature ofInstallations ................................. .4
Development Ease and the Installation ............................... .4
Development Installs vs. Production Installs .......................... .4
Introducing Windows Installer .....................................5
Transactional Behavior .............................................. 5
Repair ............................................................. 6
64-bit ............................................................. 6
Sharing Files ....................................................... 7
System Integration .................................................. 7
.NET .............................................................. 7
For the System or for Current User .................................... 8
Security ofInstallation vs. Security of Product .......................... 8
Updating and Deploying New Versions ................................ 8
Advertisement ..................................................... 9
Running Your Own Code ............................................ 9
The Tools ............................................................ 9
Summary ............................................................ .10

v
Contents

Chapter 2 Building an MSI File:


Visual Studio and Orca ........................ 13
Background . ......................................................... 13
Building a Package ................................................ 14
A First Look at Shortcuts ............................................ 18
More About Properties ............................................ .20
GUIDs: Product, Upgrade, and Package Codes .........................22
Into the Package with Programming ...............................25
Summary .............................................................30

Chapter 3 COM in the Windows Installer World ....... 31


LetJs All Share ....................................................31
Installing a COM Server ...........................................33
Type Libraries .....................................................36
InprocServer32 Entries and Repair ................................... 38
COM Server Dependencies ......................................... 38
Windows Installer Sharing ........................................ 38
Merge Modules and Sharing ........................................39
Building a Merge Module .......................................... .40
Relative Paths and Side-by-Side COM Components ............... .42
A Detour: Locating Components .................................... .43
Back to Side by Side ............................................... .44
Summary .............................................................48

Chapter 4 Searches and Conditions ....................... 49


Searches and Launch Conditions .................................. .49
File Search ........................................................ 52
Registry Search .................................................... 55
Component Search ................................................ 58
More Uses for Conditions ......................................... 59
Conditions and Transitive Components ............................ 60
Persisting Properties ............................................. 63
Summary ............................................................. 65

Chapter 5 Sequences of Events and


Custom Actions ................................... 67
The UI Sequence .................................................... 67
AppSearch and LaunchConditions Actions ............................ 68
IsolateComponents Action .......................................... 69
The Forms ........................................................ 69

vi
Contents

The Execute Sequence .............................................. 69


The Windows Installer Service .................................... 74
Using the Windows Installer Log ................................ 74
Custom Actions ................................................... 79
Creating a Custom Action .......................................... 79
Calling a Custom Action DLL ....................................... 86
Passing Data to a Deferred Custom Action ........................... .90
Executable Programs As Custom Actions .............................. 94
Security and Custom Actions ...................................... 96
Preserving the Installation Location with a Custom Action .... 97
Custom Actions in the UI Sequence ............................... 98
Custom Action Scheduling ......................................... 100
Uninstall Custom Actions and Conditions ...................... .101
Commit Custom Actions ............................................ 101
Rollback Custom Actions .......................................... 102
Type 19: Terminating the Installation .......................... 102
Installing and Embedding Other MSI Packages ................... 103
Using TYPe 7 and TYPe 39 ......................................... .103
Using TYPe 50: Launching an Executable to Install a Package ........... 106
Calling Custom Actions with MsiDoAction ...................... .107
Conditions on Custom Actions .................................... 108
Installed ........................................................ .108
REMOVE ....................................................... .108
Component and Feature Conditions ............................... .109
The Interaction of Properties, Conditions, and Installation State ........ 109
Summary .................................................. ......... .110

Chapter 6 How Do You Fix It? ............................ 111


The Major Upgrade ................................................ 111
Preserving Data Across Major Upgrades .......................... 118
Minor Upgrade by Reinstalling ................................... 119
Component Rules and the Minor Upgrade ........................... 122
Versions and Version Lying ......................................... 123
Minor Upgrades and Data Files ..................................... 123
Companion Files ................................................. 126
Uses of Minor Upgrades ........................................... 127
Summary ............................................................ 128

Chapter 7 ASP. NET Setups .................................. 129


The Web Project ................................................... 129
which Web Site Is Used? ......................................... 138

vii
Contents

But I DonJt Want to Use the IIS WWWRoot Folder ............... 138
lIS and Its WMI Provider ........................................ 138
Summary ............................................................ 139

Chapter 8 Installing •NET Assemblies .................. 141


Assemblies and Sharing ........................................... 141
Installer Tables and Assemblies .................................142
Component ...................................................... 142
Feature .......................................................... 143
File_Manifest .................................................... 143
File_Application .................................................. 143
Attributes ....................................................... 143
Installing Assemblies ............................................ 144
What About Gacutil.exe? ........................................... 146
Why Use the GAC at All? ........................................... 147
Exposing . NET Class Libraries to COM Clients .................. 150
Downstream Dependent Assemblies ................................ 155
Creating Side-by-Side .NET COM Components ....................... 155
Assemblies and CAs ............................................... 162
Summary . ........................................................... 166

Chapter 9 Installation Design ............................ 169


Installation Prerequisites ...................................... 169
Does the Application Need It or Does
the Installation Program Need It? ...............................169
What Does the Application Do If the Prerequisites Aren't Met? .......... 171
Redistributables As Programs .................................... 171
Other External Installations .................................... 174
Merge Modules ..................................................... 175
The User Interface ............................................... 176
Use Windows Installer Public Properties ............................. 176
Use Transforms to Specify Install Behavior ........................... 176
Delay Collecting Application Data Until the User Runs the Application .. 177
Collect the Information Before the Install Runs ....................... 179
Application Design and the Install ............................. 179
The Application Must Return Meaningful Error Messages .............. 181
Features and Components ..........................................182
Summary ............................................................ 184

viii
Contents

Chapter 10 Windows Services ............................... 185


Service Installation ............................................. 185
StopServices ..................................................... 186
DeleteServices ................................................... 186
InstallServices .................................................... 186
StartServices ..................................................... 186
Installing Win32 Services ....................................... 186
ServiceInstall Table ............................................... 187
ServiceControl Table .............................................. 189
What Could Go Wrong? ............................................ 191
Other Ways to Control Services ..................................... 192
Installing .NET Services ......................................... 192
Should You Use .NET Installer Classes? ........................ 197
Summary ............................................................ 199

Chapter 11 The GAC and Updating Assemblies ........... 201


The GAC ........................................................... .201
Why Use the GAC? ............................................... .202
Why Is Assembly Version Important? ............................... .203
Major Upgrade into the GAC ...................................... .203
Minor Upgrade into the GAC ...................................... .204
Using File Version to Update a GAC Assembly ....................... .208
Policies and Redirection ........................................ .209
Summary ............................................................210

Chapter 12 Updates Using Patches ....................... 213


What Is a Patch? .................................................213
Creating a Patch ..................................................213
Creating the Administrative Install Images ........................... 214
Creating the PCP File .............................................215
Running MsiMsp.exe ............................................. .220
Applying the Patch ............................................... 221
Patching Mul tiple Products ......................................223
Patching Tips .....................................................223
Uninstalling Patches .............................................225
Transforms . ........................................................225
Summary ............................................................226

ix
Contents

Chapter 13 Installation Environments ................... 227


Advertised Installations .........................................227
Privileges and Managed Applications ............................230
Installing from the Internet ....................................231
Security and Advertising with Transforms ..................... .232
SDK Internet Tools: MsiStuff.exe and Setup.exe .............. .233
Installing on Terminal Server ...................................234
Installing on Windows 64-Bit ....................................235
64-Bit Installer Packages ........................................... 236
64-Bit Custom Actions and Searches ................................ 237
64-Bit Folder Properties ........................................... 237
COM Registration and Packaging Tools .............................. 238
Embedded DLLs ................................................. 238
What About 64-Bit.NET Assemblies? " ................... " ., ...... .239
Summary ............................................................239

Chapter 14 How- Tos, Tips, and Gotchas .................. 241


How To ... ..........................................................241
Find Dependent DLLs ............................................ 241
Prevent Repair with a Null Component GllD ........................242
Show FilesInUse Dialog .......................................... .242
Find In-Use Files in the Log ................................. , ..... .244
Uninstall Broken Packages ......................................... 244
List Windows Protected Files ....................................... 245
Install Performance Counters ..................................... .246
Use Properties in the Standard Dialogs .............................. 246
Log an Uninstall .................................................. 247
Stream Data from the Binary Table ................................. 247
Find Updated Files in the Log ...................................... 248
Disable All Advertised Shortcuts ...................................249
Check for Privileges and Administrative Rights .......................249
Validate a CD Key Serial Number .................................. .250
Run a Program at the End of the Install .............................. 254
Advice .............................................................254
Use ARPINSTALLLOCATION to Save the Install Location .............. 255
Custom Action DLLs Are Versatile and Easy ......................... .255
Ignore Dialog Errors in Logs ....................................... 255
VBScript Custom Actions Are Easy .................................. 256
Common Errors and Why You Get Them ............................ 256
Test the Install on a Clean System ..................................258
Look at XML for User Settings .....................................259

x
Contents

Warnings .......................................................... .260


VBScript Custom Actions Are Not Windows Script Host ............... .260
Msiexec Command Line Is Picky ................................... .260
Services and Environment Variables ................................ .260
Changing the Product's Uninstall Behavior .......................... .261
Services and Remote Computers ................................... 261
ResolveSource and the Original Install Package ...................... .261
Your Custom Action Won't Run As System Account ................... .262
Bootstrappers and Temp Folders ................................... 262
Raising Privileges During Custom Actions ........................... .263
Use Unique Property Names ....................................... 263
Summary ............................................................264

Chapter 15 Exploring the Installer APIs ............... 265


WMI .................................................................265
UsingWMI to Install a Product ..................................... 267
Listing Products with WMI and the .NET Framework .................. 268
WMI or the Installer APIs .......................................... 269
The Installer APIs .............................................. .270
Types of Installer APIs ......................................... .275
Summary ............................................................276

Chapter 16 Tools and Futures ............................. 277


Development Tools ................................................ .277
What About Visual Studio? ....................................... 279
Futures ........................................................... .280
Where Are Improvements Needed? ............................... .280
Summary ............................................................281

Index ..............................................................283

xi
About the Author
Phil Wilson graduated from the University of Aston, Birmingham, England,
with a BSc in chemistry, but preferred computers to test tubes and eventually
worked for 15 years on developing operating systems for Burroughs and Unisys
mainframes. Phil started programming for Windows in the early 1990s and has
developed in MFC, ATL, COM, Visual Basic, and C#. He has been involved in
installation design and technology for about eight years, and became a Microsoft
MostValuable Professional for Windows Installer in 2003. To get away from com-
puters, he plays and records guitar, and enjoys camping in the California desert.
Phil works for Unisys Corporation in Mission Viejo, California.

xiii
Acknowledgments
Many thanks to the people at Apress for giving me this opportunity, especially
Dan Appleman. Thanks to Tracy Brown Collins, Susannah PfaIzer, and Kari
Brooks for getting me through it all. A lot probably goes on in this process that
they kept me blissfully unaware of; all I had to do was keep writing.
My heartfelt thanks go to Chris Gouge and Carolyn Napier of Microsoft for
their technical review. They patiently corrected my misunderstandings, and the
book is much better for their review. I can't imagine what it must feel like to have
someone write a book about the software that you work on every day, so to them
and the rest of the Window Installer team: I hope I've done a good job.
Thanks also to R. Michael Sanford for his early review work.
Finally, thanks to my family for their patience while I was holed up evenings
and weekends for the duration, and thanks to my friends M.G., AK., and Y.R. for
believing in me.

xv
Introduction
Installing new software is perhaps the most adrenalin-inducing experience
you'll have on a computer, aside from whatever games you might play. It's not
hard to see why. You give over control of the system to a program that often
demands Administrator privilege and that then starts updating some of the most
fragile parts of your system. You might know the actual product being installed
quite well, but there's rarely any documentation about what the installation of it
will do to your system. It might install kernel drivers or Services, it might alter
your personal settings without your permission, and it might result in other
applications on your system no longer working. For a company building and
shipping software, the installation might be the first time the customer has seen
your product or your company, and it's your opportunity to make a lasting
impression one way or the other. An unreliable installation will affect the cus-
tomer's image of you for a long time.
The goal of this book is to show you how to build safe and secure installa-
tions. Its focus is Windows Installer technology on the Windows NT series of
operating systems for Windows 2000 and above, and you'll build example pro-
jects as Visual Studio Setup and Deployment Projects. Aside from the actual nuts
and bolts of building Windows Installer-based installations, I'll offer advice on
how to build a reliable installation and what you should and shouldn't do. The
integration of installer technology as part of the Windows operating system
means that the dividing line between an application and its installation has
become much less sharp, and the book will cover how you need to design
applications to integrate properly with Windows Installer.
The book starts with basic principles and drills down deeper in later
chapters. I start with the installation equivalent of the "Hello World" program,
and then gradually get deeper into the contents of installer MSI files, including
installation in the .NET Framework world. Along the way I'll stop to look at best
practices and how to keep your installation reliable. Where I show use of the
installer APls, I'll use VBScript for the sake of simplicity and clarity, but I'll also
point you at the Win32 equivalents and show you a couple of ways to call them
from the .NET Framework language C#.
As is often the case when you try to explain something, you find that you
test your understanding, and if you're lucky you learn something new at the
same time. I hope you learn as much from reading this book as I did writing it.

xvii
CHAPTER 1

Installations Past,
Present, and Future
IT OFfEN SEEMS that the installation of a product is almost an afterthought.
Developers spend hundreds oflabor-months building that great new three-tier
application. However, I wouldn't be surprised if you're reading this book because
you're the person who has to figure out how to install the application while
everyone else is out celebrating the fact that they've finished it. Of course, an
application isn't actually finished until you can install it on your clients'
systems.

Background
Many people see installations as a simple process of copying files to the client
system, but in reality, copying files is probably the most straightforward part of
the whole installation process. When installing a product on the Windows oper-
ating system (OS), you need to consider all the following areas, and this is not a
complete list by any means.

Where the Files Go


It is not always obvious where files should actually be installed. The usual con-
vention is that they get copied to the Program Files folder associated with your
company name and product name. But this isn't always the case. For example, if
your company has a set of component object model (COM) components, then
you can't usually have your own private copy in each of the product's folders.
There is only one set of COM registration entries on the system. If you install
the component at one location in one product, then at another location from
another product, the last copy of the component is the one that all the client
programs will use. That's because the install marks the InprocServer32 entry to
point to the last location the shared component was installed to. Uninstalling
anyone of the products breaks all the remaining products because the uninstall
removes the registration data when the program is uninstalled.

1
Chapter 1

Redistributing Supporting Files


Many products also need supporting software to be installed before they will
function correctly. Sometimes this means a collection of supporting DLLs or
OCXS, sometimes it means something rather complicated such as the Microsoft
Database Engine (MSDE) software. Not only that, but different operating sys-
tems have different requirements. To show a couple of examples, Windows 2000
has many of the Visual Studio 6.0 support DLLs for Visual Basic, ATL, and MFC
projects as part of the operating system, so they don't need to be installed.
However, if you're supporting Windows NT 4.0, they do. Microsoft's Visual Studio
.NET (VS.NET) has a new set of redistributables (ATL70.DLL, MFC70.DLL,
MSVCR70.DLL) that always need installing, even on Windows 2000. This area
can be confusing and contributes to the general expression for this situation-
"DLLHell."

Installing Windows Services


Wmdows Services sometimes depend on other Services that are already on the
system. Installing a Service might therefore require stopping these other
Services, installing yours, then starting up these other Services, and finally start-
ing your Service.

Files in Use
The typical problem with in-use files is that you're trying to replace them with
newer versions. It is good practice to attempt to shut down the application using
these files. If the application is a Service or an application that has a user inter-
face, you might be able to send messages to close it down (or prompt the user to
do so), but some of these scenarios can be complex. You might be trying to regis-
ter a COM DLL by calling its DllRegisterServer function (which is what
REGSVR32.EXE does). However, that DLL might require a dependent DLL that
could not be installed because an older version of that dependent DLL is in use.
In these situations the only recourse is to arrange a reboot to get the files
replaced. In the case of registering COM servers, you typically need to write an
entry to the system Registry's RunOnce key to register the DLL, and then arrange
the reboot.

2
Installations Past, Present, and Future

Security and the Target User


Installations often have to be run with Administrator account privileges because
they update parts of the system that require privileges to create or modify them.
On the other hand, say you're installing on a shared computer and you'd like to
install something on behalf of another user. Although you could go ahead and
install it with an Administrator's account, it's not clear that you want this other
user to have Administrator privileges. There is also a privacy issue on shared
computers, perhaps not so much when one individual installs something for
another, but in the corporate world where several users might be sharing one
computer. Therefore, there is often a contlict between the security requirements
of the installation and the security requirements of the installed product.

Maintaining the Product


It's a pretty safe assumption that sooner or later a product will need updates,
whether they are bug fixes or feature additions. You need a mechanism that can
identify where the existing files are located on the client system and replace
them with new versions. This maintenance requirement has all the drawbacks
you already looked at relating to files in use and so on, with the additional diffi-
culties of working out what to do if the update fails. This can mean identifying
the files that are to be updated, and backing them up somewhere. That way the
user can restore them if the update fails or if the user finds that the updated
product is broken and needs to uninstall the update. This is the model used with
Windows Service Packs. Because of these possible requirements, this type of
service pack installation is sometimes different than the original installation,
and you may use a different tool to build it. It would not be unusual for an
installation developer to need to understand at least two types of installation-
the original product installation and the tools that build it, plus the tools to build
service packs.

Environments
For example, if a product consists of three distinct tiers, there are likely to be
three distinct environments onto which you have to install some piece of the
application. Perhaps you need to divide the product into separate features, one
per environment. Perhaps files or programs are common to some of the tiers, so
you would need to break out these common files into some kind of separate fea-
ture (not visible to the user) that can be installed on all the tiers by default. Each
tier might also be a different type of Windows environment. For example, the

3
Chapter 1

back-end tier might require a server operating system, so you probably don't
want to allow it to be installed on a workstation. In other words, the application
needs to be broken up into pieces and rebuilt as a set offeatures that can be tar-
geted at the appropriate user or platform.

The One-Way Nature of Installations


Although you usually call an installation program a "program," it's not like other
programs in a couple of interesting ways. If you have an application program
that has a bug, you ship a fix to your clients, who replace the old version with the
new one and start running the new version. Installation programs aren't like
that. If you've shipped a broken installation, you can't just ship a corrected one
to your clients and ask them to use it. That's because no program on the client's
system can be replaced-it's not literally a program in that sense. In reality, an
installation is a process, a sequence of actions that alter the target system, and
once the installation has done its work you can't just replace it with a corrected
(updated) version. There is also the uninstall process to keep in mind. Once the
product has been installed, then so has the uninstall process, so it's essential that
the uninstall process work properly. A product that cannot be uninstalled is
potentially useless if fixing or replacing it requires users to uninstall it.

Development Ease and the Installation


Development tools make it easy to build programs. You use a wizard, add some
code, and your system is already set up with the support necessary for you to
test the program. I'm exaggerating somewhat, but the point is that when you
install the program or application on a client system, you need to know about
each file, supporting DLL, and Registry entry that the application needs for it to
run. If you're communicating this to someone who's building the installation
program, detailing everything that's needed is a nontrivial task.

Development Installs vs. Production Installs


Development environments and documentation frequently talk in terms of
command-line programs that perform installation tasks. In COM, developers are
used to the idea of running Regsvr32.exe to register COM DLLs, or a -Regserver
command-line argument to register a COM local server. In the .NET Framework
world you see references to running Regasm.exe, Gacutil.exe, and Installutil.exe
to install assemblies for .NET COM Interop, to install assemblies into the Global

4
Installations Past, Present, and Future

Assembly Cache (the GAC), or to register assemblies as .NETWindows Services.


However, not one of these command-line programs is necessary for a Windows
Installer-based installation because installer support is provided for the func-
tionality offered by these programs.

Introducing Windows Installer


Before Windows Installer there was no specific Windows functionality supplied
to install products. (Strictly speaking, there has always been the Setup API, but
its main functionality is based on using INF files to perform installations.) The
Windows programming environment happened to be rich enough that develop-
ers could use its APIs to perform installs. A major consequence of using the
general-purpose Windows APIs was that there was no consistent integration
between Windows and the installed product. For example, if you wanted to
inventory the products installed on a system, you could enumerate the contents
of the Registry area used by the Add/Remove Programs applet, but any number
of different tools could have installed each product, and even a simple task such
as finding where the product was installed was nontrivial.
Around the Windows 2000 timeframe, Microsoft supplied Windows Installer
as the installation technology for Microsoft Office 2000. I'll take a brieflook here
at the problems it helps solve, and a more in-depth look in later chapters.
Windows Installer provides a standard way to install, maintain, and uninstall
software. However, that by itself is not justification, so let's look at what makes
Windows Installer unique and how it addresses some of the preceding topics.

Transactional Behavior
Nobody wants an installation to get partially completed and then fail for some
reason, leaving a system in some indeterminate state. Windows Installer turns
product installations into an all-or-nothing proposition-the product is either
successfully installed on the system, or the installation does not work and all the
changes that might have been made to the system are backed out.
A large part of this transactional nature is a consequence of eliminating as
much code as possible from the installation process. As you'll see later, Windows
Installer offers features that mean you don't necessarily need to run custom code
at install time. This is necessary because otherwise you, the installation develop-
er, would be responsible for reversing any changes made to the system during
the installation.
As an example, consider COM server registration. As I noted earlier, a COM
server historically required its DllRegisterServer function to be called, and like-
wise the uninstall process would call DllUnregisterServer. This requires the COM

5
Chapter 1

server to initialize, where it might need a dependent DLL that isn't on the system
yet. Windows Installer deals with this by storing COM registration data inside the
actual installer package, the MSI file, so it doesn't need to call or run the COM
server to install or uninstall the Registry entries. Windows Installer can add or
remove the COM Registry entries whether the COM server itself is functional or
not. Installing the COM server means copying the file to the system and writing
the Registry entries from installer tables.
The same general idea applies to Windows Services (sometimes called NT
Services). When they are installed with something like a -Service command-line
argument to a run of the Service program itself, install and uninstall are depen-
dent on the Service being functional. However, Windows Installer has support
for installing Services directly from the installation package with no requirement
to run the Service executable to install it. Consequently, installation and removal
of the Service are controlled more safely.

Repair
It's not unusual for files that belong to a product to get accidentally deleted.
Windows Installer has repair features that restore an application that is broken
because of missing files or Registry entries. If the installation marks a file or a
Registry entry as "key," Windows Installer has the capability to restore the file or
entry automatically if it's missing. When you go to Add/Remove Programs, a
Repair choice is offered, along with other choices to uninstall or modify the
installed features.
Repair is probably the feature that most often surprises developers. They are
generally familiar with the idea that a product can be installed and then manip-
ulated afterwards by adding new files or removing unwanted ones, only to find
that the repair mechanism restores the files or Registry keys to the initial instal-
lation state. Users too are sometimes surprised when they remove a shortcut and
move it to some other location, only to find that Windows Installer restores it
through a repair.

64-bit
There is support in Windows Installer for installing applications onto 64-bit
Windows operating systems. This doesn't just mean that you can install 32-bit
applications onto 64-bit systems, it means that Windows Installer is likely to be
the only way to install 64-bit applications onto a 64-bit system.

6
Installations Past, Present, and Future

Sharing Files
Sharing has always been an important aspect of installations. The sharing issues
are largely responsible for the situation popularly (or unpopularly) known as
"DLL Hell." You need to work out which Microsoft DLLs need installing to sup-
port your product, and consequently run the risk of creating an incompatible set
of system DLLs. Or you might have shared components in your company's prod-
ucts that all need to be installed and managed correctly on client systems. This is
becoming less of an issue since Windows 2000 introduced Windows Protected
Files, a feature that prevents installations from replacing critical system files.
Windows Installer does not even attempt to replace those protected files that are
considered to be part of the OS.
Sharing in Windows Installer uses reference counts for each unique compo-
nent. You still need to follow rules, as you'll see later, but the Windows Installer
component sharing mechanism is much more robust than previous schemes.

System Integration
Products installed with Windows Installer are integrated into Windows. APIs and
COM objects can report information about installed products to a detailed level.
In addition, a Windows Management Instrumentation (WMI) provider reports
the content and configuration of installed products. If you ever wondered
whether there is a way to discover accurately what products are installed on a
system, the fact that there are standard API calls is a vast improvement com-
pared to prowling the Registry looking for products. These APIs not only return
detail about potentially every file installed by a product, they also allow the
application code itself to integrate with the installation and modify installed
components on the fly. The APIs also allow access to installation packages (MSI
files). For example, it's relatively easy to query the contents of an installation
package and compare the contents with a version of that package that is
installed on the system.

• NET

Windows Installer has built-in support for installing .NET assemblies into the
Global Assembly Cache (GAC). This is likely to be the only way you should install
assemblies into the GAC. Yes, Microsoft supplies the Gacutil.exe utility in the
development environment, but this program knows nothing about the Windows
Installer reference-counting scheme, so shared assemblies installed into the GAC
require Windows Installer to maintain correct shared-installer reference counts.

7
Chapter 1

For the System or for Current User


When you start installing a product you are often asked if it's being installed
for you (private to your account on the system), or whether it's being installed
for everyone. These generally affect whether, for example, certain Registry
entries are written to the HKEY_CURRENT_USER (HKCU area) or to
HKEY_LOCAL_MACHINE (HKLM). Uyou assume that the target user is in fact
the current user of the system, this means that the application should not be vis-
ible to other users. But think about the mechanics of COM registration, where
code in the DllRegisterServer entry point creates COM registration entries on the
system. You'll realize that there is no way that the code in DllRegisterServer
knows whether the installation is per-user or per-machine, so the registration
code cannot know which Registry location is the correct one, HKLM or HKCU.
The code in DllRegisterServer registers to the local machine Registry keys, so in
effect an install for the current user leaves COM servers accessible to everyone
on the system. It therefore makes a lot of sense to get COM servers out of the
business of self-registration and have Windows Installer create the registration
entries in the appropriate Registry location.

Security of Installation vs. Security of Product


When trying to install a product for a user who might not have the security privi-
leges to install the product, there needs to be a way for this user to install the
product without requiring those elevated privileges on a permanent basis.
Windows Installer provides some ways to deal with these issues. One reason it
helps with these issues is because it runs as a Windows Service and doesn't need
to be constrained by the privileges of the current user. Another reason is because
policies can be configured so you can perform an installation with elevated priv-
ileges on behalf of a user who is not privileged.

Updating and Deploying New Versions


Before Windows Installer, when you wanted to ship corrections to a product,
perhaps you simply rebuilt the entire installation setup and sent it to your
clients. However, you can't just ask your client to install the product, because
you'd end up with two copies of the product on the system. However, if you're
supplying a fix or an update you need to replace the existing installed product.
Generally speaking, the incoming new installation would detect the existing one
and uninstall it, or perhaps even arrange to completely install itself on top of the
existing product. Another choice would be to produce a service pack to update

8
Installations Past, Present, and Future

the product, often requiring use of a separate tool to install the updates to the
client system. To summarize, there have been a number of ways to deal with
these maintenance issues. Windows Installer has some formal mechanisms for
installing product updates and fixes.

Advertisement
You can think of advertisement as installation-on-demand. It can be particularly
useful in corporate environments-you can have practically everything installed
(shortcuts, Registry entries, and so on) except for the files. When you reference
the advertised product, the installation starts installing the files from a network
location onto the client system. Even after a product has been installed, perhaps
some of its features will be advertised, so that when the advertised feature is first
used this feature is installed.
The idea of advertised features is that you install a hook of some kind, typi-
cally a shortcut. Using this shortcut causes the feature to be installed. If the
advertised feature consists of one or more COM components, there is a similar
advertisement installation step that causes the component to be installed.

Running Your Own Code


Many of the observations made in this chapter might give the impression that
you can't add your own code to the installation process. In fact you can-when
you do this it's called a custom action. Many types of custom actions allow you
to run VBScript, executables, and call into a DLL, to quote a few examples. So
that changes to the system can be provided with transactional behavior in mind,
you can associate these custom actions with the install, the uninstall, and also
the rollback process that occurs when an installation fails and everything done
to the system is being undone to restore the system to its original state.

The Tools
Windows Installer packages have the MSI file extension, and the Windows
Installer Service installs these packages. You can use an SDK here, just like in
many other aspects of Windows programming. In this case, you use the Windows
Installer SDK, which is part of the Platform SDK. This contains documentation,
tools, and sample code to create and modify installer packages. VS.NET offers
wizards and a development environment to build installation packages.
Third-party vendors who provide tools to create installation setups have
been around for a while (for example, InstallShield Software). These companies'

9
Chapter 1

tools historically have built installation packages that differ from one another,
although most generate a wizard-based approach to the installation process. The
inner workings of the install-the code, the log files and so on-are all propri-
etary.
Mer Microsoft introduced the Windows Installer Service, these vendors
introduced tools to create installer packages (MSI files). Apart from companies
and products such as InstallShield, Wise, OnDemand Software's WinINSTALL,
Zero G Software's InstallAnywhere.NET (formerly ActiveInstall), and Corner
House Software, there are open source and free tools that you can use to build
installer packages. Although this book uses VS.NET extensively for its samples, it
is important to realize that Visual Studio Deployment Projects provide just a
basic authoring tool for creating packages compared to some of the more
advanced third-party products. It's quite likely that you or your company will
want to build installer packages using features that Windows Installer provides
but that are beyond the capabilities of Visual Studio Deployment Projects.
Although this book will help you build and use installer packages, you'll find it
much easier to build more complex installation packages using a fully featured
tool with support for your required functionality built into its Integrated
Development Environment (IDE). Everything you learn in this book about
Windows Installer will be useful no matter which tool you eventually decide to
use, but you'll find that the right development tool makes the process of
building installer packages easier and faster.

Summary
Perhaps the most important characteristic of an installation package (installer
terminology for an MSI file) is that it is a database. This is not loose terminology;
it really is a database with tables organized into columns and rows. As you'll see
later, you can even use SQL-like statements to query or update the installation
package. The tables in the package describe the files, features, shortcuts, Registry
entries, COM classes, and your custom action code, to name some of the con-
tent. Even the order in which activities occur during the installation process is
determined by tables that contain each action and its order relative to other
actions.
As you'll see as you progress through the following chapters, Windows
Installer supplies a framework for installations. like most frameworks, it works
best when you don't bend it. When you design and develop applications, you're
almost certainly aware of the limitations and capabilities of the implementation
you're going to use, and you take these into account when you design the appli-
cation. The same is true of Windows Installer. If you come to design a product
installation, you must be aware of the direction that the technology would prefer

10
Installations Past, Present, and Future

you to take. It's probably no exaggeration to say that most installation problems
are the result of a preconceived design or implementation plan that doesn't fit
the framework.
You'll see how all these examples work using actual examples of installation
packages, so let's get going and build your first installation package.

11
CHAPTER 2

Building an MSI File:


Visual Studio and Orca
IN TIllS CHAPTER, you'll build an installer package using a VS.NET Setup and
Deployment Project and look at it with a tool called Orca, part of the Windows
Installer SDK.

Background
First, some history and an overview ofVS's capabilities in the installation area.
Microsoft has often added capabilities for building installations in VS-per-
haps you've used the Visual Basic Package and Deployment Wizard. If you've
used VS 6.0, you might have used the first version of Visual Studio Installer,
which was available as a free download for VS licensees. VS.NET is the first
release ofVS that integrates the ability to build Windows Installer packages
with the IDE. However, VS.NET's installation tool comes with some limitations
and restrictions that become apparent as you use it. This doesn't mean that
Microsoft did a bad job, but it does mean that if you want to use a substantial
set of Windows Installer's features, you should look beyond VS.NET's installer
tool. Look in Chapter 16 for a list of some of the vendors that supply fully
featured tools to create installer packages.
One ofthe tools that Microsoft supplies to view and modify installer pack-
ages is called Orca. You can find it in the Windows Installer section of the
Platform SDK; the installation package is (what else?) an installer package called
ORCA.MSI. After you've installed it, you'll find that the right -click context menu
on Windows Installer files (notably packages, MSI files and merge modules,
MSM files) allows you to open and edit them. You'll be using Orca later to view
and modify installation packages.
I'll describe everything I cover here regarding Windows Installer concepts in
more detail in later chapters. In this chapter, you'll build an installer package so
that you can look inside the actual MSI file; that's when you'll use Orca.

13
Chapter 2

Building a Package
The first package you build is a simple one-this is the "Hello World" program's
equivalent in the installation context. You'll install Notepad (NOTEPAD.EXE)
and a text file, together with a shortcut to run the installed Notepad against the
text file. Note that this project is supplied with the book, so you can build it
yourself or use the one provided.
You start by runningVS and choosing the New Project from the File menu,
selecting Setup and Deployment Project, and then Setup Project. Once the wiz-
ard has completed, select the Project icon in the Solution Explorer. The Edit
menu has drop-down choices for View >- Editor >- File System. When you're in
this File System view, you can then select Application Folder. Then you can
right -click in the file pane and select Add, then File. Add NOTEPAD.EXE and
SomeTextFile.txt in that pane. Because you'll need a shortcut to NOTEPAD.EXE
for the Programs menu, right-click NOTEPAD.EXE in the file pane that you just
added it to, and choose Create Shortcut. At this point you should see something
like Figure 2-1. Notice that this view also shows the Properties window for the
Application Folder, where ProgramFilesFolder, Manufacturer, and ProductName
are enclosed in square brackets. These are three standard Windows Installer
properties. You'll see more of these later because properties are the variables
that drive the behavior of an installation. For now the important thing to know
is that the value of [ProgramFilesFolderj is resolved when the installation runs
and is replaced with the Program Files path on the system. Those square brack-
ets mean that the identifier they contain is a Windows Installer property.

• -, I , , ,. . " j'-. I .. :.. X

-
file Ed4 l/OeVi frOJect aull<l J!ebug rools 6tbon !i!l'ndow Help
,iJ. ~ ~ ",Ie_ - ~ ~lftg ~3 ::
SolulJon EJcpIor.. ~ X file SYStem (Trylfolepad) I 4 ~ x

:$'::I~~. 1M Fit SyS«m on Tll1;Iet lIactone Uame Type


~~n 'Tryllo .pad' ..lI ' I. ' ! ...l OOmAD.EXE FiO
- i;l Tryllote",d .,J USt'. Deol<top ~ S'lortcut to IIOmAn ... S~ottcut
• ~ USt~. Progoms Monu .jSOmoTtxtF .M Fio
• ...J Detected De~1
..luOTEPAD.EXE
.J SOmeTe><tF".~ ~
IApplication FoIdu Fol. 1II11,"bon PIOPflbts 3
CJ!j~
8M'"".
W:an'lf
Alw,aysCrtat.
:rnon F¢I! ••

CondotiOn
Defaultlocluon [ProQ_~~ttl[ManufaClUret)\[ProduCllIarne)

Tr.lnSI'b'lf Faile

Hlse

(I I .!1 .-
Ready h

Figure 2-1. VSS Application folder with shortcut

14
Building an MSI File: Visual Studio and Orca

You need the shortcut to Notepad for the User's Programs Menu, so right-
click that shortcut and select Cut. Then right-click the User's Programs Menu
item, select Add >- Folder to add a folder and a subfolder (I called it Phil and
TryNotepad), then use Paste to get the shortcut into the pane. You'll see some-
thing like Figure 2 -1.
Before you do a build, right-click the Project in the Solution Explorer and
set the build properties to package files "In setup file." Options are here for
bootstrappers (in other words, making sure that the Windows Installer engine is
installed on the target system) , but you'll just be building the installer package,
an MSI file. See Figure 2-2 for an example of the property pages for the build.

Qebug rools Window l:Ielp


sIlItreg
FIle System (Tryllotepad) I I ~ x
fie System on T.,get ",.chlle 1:'1",:1.~me,,-:--~-:-:~_---,-:TJ.f;"-e_ _ _ _ ;
S~n 'TrylloteP~d' (I prole ..:l Appkaoon Folder ;..,JAppkaOOn Folder Folder
- ID TryUote~d .:l use(s Desktop ..:lUse~s Oesktop Folder
• ...J Detected Dependenoes • .:l Use(s Prog",ms "'enu .,JU.e~s Progr.lms Menu Folder
, IIDTEPAD.EXE
Tryllotel"'d Property Pages x

r Autllenocode SIOnature

L.......I.._ _---Jl!J
OK

Ready

Figure 2-2. VSs build options

Now if you do a build it should create an installer package: an MSI file


containing everything needed to install your Notepad application. You can now
double-click the package and the installation starts. After the Welcome screen,

15
Chapter 2

you see a Select Installation folder that's got some notable features (see
Figure 2-3) :

Select Installation Folder

The ,nstallerwlll,nstall ToyNotepad to the follOWIng folder.

To install 10 this folder. dick 'Next". To ,nstall to a dofferent folder. enter II below or click 'Browse'.

Eolder
1C:\Program Files\PhII\ToyNotepad\ Browse

Install TryNotepad (or yourself. or (or anyone who uses thiS computer.

r Everyone

Ii Justme

Cancel <6ack

Figure 2-3. Selecting the installation folder

• The installer has resolved the ProgramFilesFolder property and the Folder
box shows the actual path on the target system. This is a key feature of
Windows Installer properties-not so much that they are resolved but that
you can use them in square brackets in places such as folder names and
Registry entries. I should point out that this folder isn't always C:\Program
Files, which is why Windows Installer supplies a variable property.

• The dialog wants to know whether you want to install this application for
Just me or for Everyone. In other words, should this be installed for the
current user or for all users of the system? This choice affects an impor-
tant Windows Installer property that you can control-the ALLUSERS
property you'll look at later.

Select Everyone and continue. The installation should complete normally,


and the Start Menu should now have the shortcut to initiate Notepad. You can
uninstall the product in the usual ways via Add/Remove Programs, or by right-
clicking the package and selecting UninstalL However, you're going to look at
the content of the package, so after you've installed Orca, right -click the package

16
Building an MSI File: Visual Studio and Orca

and select Edit with Orca. What you see is a screen like Figure 2-4, where Orca
shows each installer table in the left pane and the rows and columns of each
table on the right. (Figure 2-9 shows a view with more tables shown.) In the case
of Figure 2-4, Orca is showing the File table because it's a useful place to start
dissecting a package.

- • TryNotepad.rnsi - Orca r;-


fie i;dt T~ Tr.msform 10015 'bINI ~

Dl~1 I
NOTEPAO.EXEINOTEPAO.EXE 50960
SONETEN 1.TXTISomeTextFle.txt 36

ICon

~__._• ..:.J !:;~======,,~==______---;---I _ _---,_ _~.£l


.
Tables: 87 fie· 2 ro....s No cdJmn IS ~ed. ~

Figure 2-4. The File table

Before you go any further, the tables and their contents, including the
details of each table and column, are documented in the Windows Installer sec-
tion of the Platform SDK. I'm generally not going to repeat all that detail; I'll just
point out how the tables work and fit together so that you can make more sense
of the documentation.
Notice that there is a row for each file you're installing, and that each row
has the name of a file in the FileName column. If you hadn't guessed from the
format, the file name is shown in short file name and long file name format sep-
arated by a vertical bar. Perhaps more interestingly, the File table shows the ver-
sion for code files in the Version column (which appears only if the file has a
version resource). If you were thinking that Windows Installer uses this version
value to decide whether to replace older versions on the target system, you're
right, and you'll be using this value when you get to Chapter 6, which describes
updating products.
An important item in the File table is the Componenc column. AWindows
Installer Component is the key unit of an installation. There is a component ref-
erence at almost every place in the package where something is going to be
installed onto the client system. VS has generated two components in the File
table, one for NOTEPAD.EXE and one for the text file. If you've installed some-
thing and selected a "Custom" install, you're probably used to the idea of a list of
features that can be selected or deselected for installation. The way this works in
Windows Installer is that a feature consists of one or more components. In fact,
if you look at Figure 2-5 you see the FeatureComponents table, which is where
components get mapped to their owning feature. Notice thatVS generates only

17
Chapter 2

one feature, called DefaultFeature. This is one of the limitations ofVS: It has no
capability to organize an installation into more than one feature. You also see
more than just the two components in the File table here. It turns out that VS
wants to be sure that the Program Menu folders get removed at uninstall time. It
adds a component and some entries in the RemoveFile table to make sure that
the Program Menu subfolders get deleted, and it creates a component because
most activities done during an installation require an associated component. VS
also creates a component to deal with some Registry entries it might create
(more on this later in this chapter).

- • TryNotepad.rnsi - Orca •
Be fdlt Tjbles Transform Ioois YeN Help
DI~I I
ExtensiOn
Feature C__S267EOFDCD374FB891ESBAC45218D80B
FeatureComponents DeraultFeature C__746C69616E6711D3SEODOOC04F6837DO
Fie --1 DeFaultFeature C__BE79E3FE2B394E67A0247D9AEFSBIE84
FieSFPcatabg
Font
leon
lnlFie
lnlLocator
Tables: 87 FeatureComponents - 4 rows No collmn is selected.

Figure 2-5. The FeatureComponents table

A First Look at Shortcuts


You installed a shortcut to Notepad in this installation. As you might expect,
there is a Shortcut table in the installation package. Figure 2-6 shows the first
few columns of the Orca view of the shortcut table and the entry for the shortcut
to NOTEPAD.EXE.

-• TryNolepad.lII~ - Orca --,

Servce...
ServiCeL ..

Sgnature
TextStyle
TypeUl -1
UIText ..:J'-'~..L- ______________-'
Tables: 87 Shortcut . 1 rol'l No ~mn IS selected.

Figure 2-6. The Shortcut table


18
Building an MSI File: Visual Studio and Orca

Note that the Componenc column contains the Windows Installer


Component that the shortcut belongs to-exactly what you would expect know-
ing that all installed items belong to a component. There is also a Directory_
column, which effectively names the Program Menu folder and the sub folders
that contain the shortcut. There is also an entry in the Target column that con-
tains the name of the only feature in this installation. The fact that this is the
name of a feature in the Feature table means that this is an "advertised" short-
cut. Although advertised features are associated with the "install on demand"
scenario, they have another interesting characteristic, which is that they verify
the correctness of their associated installer components. In other words, using
the shortcut triggers an automatic repair if the components are "broken." If you
remove the file NOTEPAD.EXE from its installed location on disk and then use
the shortcut, you see a Windows Installer dialog that restores the missing file.
Although the name of the shortcut is in the Shortcut table, there is no obvi-
ous reference to the actual target file-the installed NOTEPAD.EXE. That's
because the linkage is indirect, through the component name in the Shortcut
table. If you look at the Component table in Figure 2-7, the shortcut component
is that top one, and that component has a KeyPath entry that is a key into the
File table. Referring back to Figure 2-4, you can see that this File table entry is
NOTEPAD.EXE. This is a specific case of a general principle in the installer-that
a target file is indirectly referenced by naming a component that has a KeyPath
entry referring to a File table entry for a file. In other words, the Shortcut table
names the component (not the file) , and the Component table's KeyPath entry
points to the file. There's another subtle point to notice here about the Shortcut,
which is that a shortcut file is not literally being installed. Although it might
have looked as if you were installing an actual file in the IDE-a shortcut-the
package contains no such file, just a table entry with the information required to
create one.

" -
eono.-
C_04;27151~12"'F,*12 '!IA~Bl0
C_tI28>a1fOCO>'... I\et'EIlIWlm' .....
[C18tW)311·2111-~ 17
(1l1>~221£~1Of.72I'2'8CJ
8011fD1A2f'IJ TARO£TDIR
TAAOETt1Il
_00I211$1C1S:1I204-Fcee'2'~~IO
_8287EOI'DaXl74feao'EeeACAl2' .....
Cooud !J C_718C11811f1711D38£0IXI0CCMf.,7DQ [B3f:II!tMI!:-oas-fJlO.t!FI2"'78IS1115CD1B) T~

...--
~

~
~
0000g

_of..
o-o.y
=.I
o.<.~

Figure 2-7. The Component table

If you look at this actual shortcut with Open All Users in Explorer, it looks
like Figure 2-8. Compared to noninstaller shortcuts, the Target is grayed out and
can't be altered. This is because this shortcut is encoded with the special behav-
ior that causes Windows to verify the presence of the installer component.

19
Chapter 2

Shortcut to NOTEPAO.EXE

Tlirget type: ApphClltlon

S,tllrt In: I "C: \ Progrllm Flles\ PhII\TryHoteplld\"

Shortcut key: INone

Bun: It~ormal w indow


C2mment:

A!1vanced ...

OK Cancel

Figure 2-8. A Windows Installer shortcut

More About Properties


Windows Installer properties are the variables that you use to interact with
the installation, such as the ProgramFilesFolder property I mentioned. They're
somewhat similar to Environment variables in the sense that they are text-based
variables that define other text, standard ones are provided by Windows, and
you can define your own and sometimes set the Windows ones. You'll be
looking at properties in detail later, but be aware that they have some important
behaviors:

1. Properties are case-sensitive. If you create your own property name and
refer to it later, be sure that you get the case correct.

2. A property can be public or private. A public property must be in


uppercase. If it's public, you can specify it with a value in a command-
line install of a package. Also, because of the way that installations work

20
Building an MSI File: Visual Studio and Orca

internally, a public property that you create is also visible throughout


most of the installation sequence. You cannot specify private properties
in a command-line installation and you can't propagate them through-
out the installation sequences (covered in Chapter 5).

3. You can treat properties as if they were logical values or data values. I'll
use the built-in VersionNT property as an example. This property tells
you whether the system you're installing on is in the Windows NT family
(NT, Windows 2000, Windows 2003, Windows XP). For example, any-
thing you do that depends on Windows Services can be conditioned on
VersionNT as if it were a Boolean-valued attribute. It's not unusual to
see VersionNT as a condition in these situations. However, if you look at
the actual value of this property you'll find it returns the version of the
NT family that is running. On Windows 2000 this property has the value
500, and on XP the value 501. In other words, it can be used as a
Boolean True/False value even though it contains a version value. If
you're a C programmer, you might be familiar with the idea that a value
is True if it is non-NULL in spite of its actual value, somewhat like the
behavior of some C language variables.

4. The data type of a property is vague. As you've seen, you can treat
VersionNT as Boolean-valued even if the actual value of it is 500. If you
wanted to check if you were running on Windows 2000 or later, you
might check for VersionNT>=500. Does this mean it's a string or a
Boolean or a number? In practice it usually doesn't matter because the
context usually defines how the data type works, but this vagueness
might well offend you if you are a programmer with a type-safe
sensibility.

An installer package-a database-contains a Property table, which is


where you can define your own properties if you need to give them default val-
ues, and also set values for standard installer properties. You aren't required to
declare your own properties in the Property table. Declare them only if you need
to give them a default value, because the act of programmatically setting a prop-
erty name to a value creates the property on the fly.
Looking at Figure 2-9, you see the Property table of your Notepad package.
The table in general is just a list of property names and property values, some
uppercase and public, some lowercase and private. Because this list contains
both user-defined (added byVS when it built the package) and Windows
Installer-defined properties, there's no way to distinguish between what is a pre-
defined installer property and what isn't, other than by looking in the SDK to see
if it's defined there. ProductName and Manufacturer are among the standard
installer properties that are defined here. Like many other properties, these two
end up on the system, where they are available to be retrieved using API calls, or

21
Chapter 2

shown to the user in places such as the Add/Remove Programs Control Panel
applet. ProductVersion is another installer property that you set, but unlike
ProductName and Manufacturer, its value is more than just informational.
When you look at upgrades and updating your product, you'll see that incre-
menting ProductVersion is a key step in the process.

- • TryNotepad.llIsi - Orca •

UpgradeCode {AOE3FD00-4838-4A98-8F60·0F7E96A28294}
ODBCOataSource ProductName TryNotepad
OOBCOrrver ProductCode {B042FSDI' 744E-4071-8241-420768FOE009}
OOBCSourceAtt. .. ProductVl'IWIl 1.0.0
ODBCTransiator ManufcKturer PhI
Patch ARPCONTACT PhI
PatchPackage ProductL1/lguage 1033
ProgId VSONETURLMSG Ths settJp requres the .NET FriIITII'\voO; ver5IOO [1]. I
Prope<ty VSOUSMSG ThIS settJp requre5 Internet informatIOn server 4.0 or
PublshCompon ... VSDUIANDADVERTlSED Ths adveltiSed applcatlon \'/1 not be ilStaIed because
RadoButton VSDNETJoISG ThIS setup requres the .NET Frame\voO; v~ [I], I
RegLocator VSOINVAUDURLMSG The spedled path '(2)' Is unavalable. The Internet Inf(
RegIStry VSOVERSION~ISG Unable to ~ becau5e a newer YersDn cI this prodL
Removefle Adl1lflMaf1tenanceForm....ActlOn Repat
RemovelnRe Marltenancel'OOn...,A.ctlOn Repar
RemoveRegi5l1y DetaultUlFoot VsdDetautulFont.524F4245_52S4_S341_4C45_534
ReserveCost FotIerForm...AIJsers ~IE
SfPCatabg ErrorO/abg Error1>talog
SefReg SfF_lJpfldratn upFldrBtn
serv1CeControi SFF_Nel'lfldratn NewFldrBtn
Serv1ceinsta1 We.Icomel'OOn_NextArgs FotIerForm
Shortcut FotIerFoon_PrevArgs WeicomeForm
SIgnature FoIderform_NextArgs ConfimlnstaForm
TextStyle ConfimlnSlllForm_PrI'VArgs FotIerForm
TypeLb AdmnWe!comeForm_NextArgs AdmhFotlerForm
UTText AdmnFotlerForm_PreVArgs AdmhWeioomeForm
upgrade AdmnFotlerForm_ extArgs AdmnContnnlnSlllForm
Verb AdmilConfimlrlstaFornLPreYArgs AdmnFotlerForm
_ValdatlOn

Tables: 87

Figure 2-9. The Property table

One of the key properties in an installation is the TARGETDIR property.


This is the property that names the product's primary installation folder. It
usually consists of a concatenation of other standard properties, such as
[ProgramFilesFolder) [Manufacturer) \ [ProductName) , which is what VS creates
as the default location for the application folder.

GUIDs: Product, Upgrade, and Package Codes


You can see in Figure 2-9 that the ProductCode property is in fact a GUID, a
unique identifier made famous by its use in identifying COM classes and inter-
22
Building an MSI File: Visual Studio and Orca

faces. It's used here simply because it's a convenient mechanism to identify the
product uniquely. It's in what is called the Registry format-text with curly
braces around it. Windows uses the ProductCode property to identify this prod-
uct uniquely, and the Windows Installer Service uses it to determine whether
your product is already present on a system.
The UpgradeCode is also a GUID that you should not change within the life-
time of a product. The idea behind UpgradeCode is that you will have major
revisions to a product over time, and each of these revisions is intended as a
replacement for the previous version. The UpgradeCode is the constant that
links these revisions together. You can think of an UpgradeCode as defining a
product family. Windows can detect whether a product containing a particular
UpgradeCode has already been installed on a client system. It provides a mech-
anism to uninstall the prior version as you install the new version, so that the
replacement is a seamless process instead of a visible uninstall followed by an
install of the newer product. Each version replaces the prior version until a
product arrives that is completely independent of the previous versions. In prac-
tice, this might be a marketing decision as much as a technical one. For exam-
ple, each new version of Microsoft Office that comes out is a replacement for
previous versions. However, if you look at the VS product line, VS.NET was the
start of a different product line-it did not replace VS 6.0 but could be installed
alongside it. If you were designing these product lines, the versions of Microsoft
Office would all use the same UpgradeCode, but VS.NET would have a different
UpgradeCode than VS 6.0. The way you build an installation to perform a major
upgrade of a previous version is covered in Chapter 6.
Each individual package-the MSI file-is also identified by a GUID-the
PackageCode. This is used to distinguish between different builds of the same
product. If you run Orca on an install package and choose Summary
Information from the View menu, you see something like Figure 2-10. This
shows the contents of the Summary Information stream for this package, and it
includes the PackageCode. (You can also see a similar display when you choose
Properties and Summary from the context menu when right-clicking a package,
except that the PackageCode is reported there as Revision Number.)
The combination of ProductCode and PackageCode is the way Windows
knows what to do if you try to reinstall the product. If you install your Notepad
package that you built in this chapter, then try to install the exact same package
again, you see that it shows a maintenance mode dialog. In this Notepad instal-
lation, this means that the setup shows a dialog with choices for Repair or
Remove. Windows knows that this product from this package is already installed
on the system, and the package itself is designed to go into this maintenance
mode if the product is already installed on the system. By definition, the fact
that you are attempting to install the same product (same ProductCode) from
the same package (PackageCode) means that you either want to repair or

23
Chapter 2

remove it. No other choices make sense in this context-the product is already
installed, after all! You can change the PackageCode by altering the Revision
Number from Explorer (right -clicking, choosing Properties and the Summary
tab) or in the Orca view of the Summary Information, then closing and saving
the file. When you attempt to install this package now, you see different behav-
ior. This time there is a message box from Windows saying that '~other version
of this product is already installed" and suggesting that you reconfigure from
Add/Remove Programs. In other words, you have to configure or remove the
existing installed product before you can install the new one. The PackageCode
determines the initial behavior here. If you change only the ProductCode in the
Property table using Orca and then try to install the package, it would go into
maintenance mode and ask for a Repair or Remove. If you change the
ProductCode and the PackageCode, Windows thinks it's a totally new product
and lets you go ahead with the installation.

Edit Summary Information .;.'

lille. ITryNo'epa~ I
Author IPhil

Subject

~omments

Keywords:

flalform: Iinlel iJ languages. 11033

Package Code: I{D3891 E58· 344 1-4768·81 89-E1AA28622358}

Schema 1200 Secyrity IRead·only recommen iJ


Source Image
file names
r Short P" Compressed
(i Long r A~min Image

OK Cancel

Figure 2-10. MSIfile summary information

24
Building an MSI File: Visual Studio and Orca

If you have built a genuinely new package containing new files, you've prob-
ably done so to have it update or replace the existing product on the system.
This is the subject of Chapter 6. For now, the point of this exercise is to demon-
strate the relationship between PackageCode and ProductCode.

Into the Package with Programming


Windows has a collection ofWin32 APls, all starting with Msi, that you can use
on the contents of installation packages. Other APls interface with Windows to
interact with the products installed on the system. There's also a COM interface
that is exposed mainly for administrators. I say this because the COM interface
is scriptable, and VBScript with Windows Script Host (WSH) can take full advan-
tage of it. You'll create two VBScripts here: The first does an inventory of the
package, and the second updates the package and modifies it. The complete
scripts are in the sample code associated with this chapter, and I'll go through
the functionality a snippet at a time. In the interests of readability, not every-
thing is declared explicitly.
The scripting interface into Windows Installer uses a ProgID of
"Windowslnstaller.lnstaller", so first a VBScript creates the interface with code
such as this:

Dim installer
Set installer = CreateObject ("Windows Installer. Installer")

Note that I'm skipping the error-checking code in these code fragments.
With an Installer object, you can now open a database package:

Dim database
Const msiOpenDatabaseModeReadOnly = 0
Set database = installer.OpenDatabase
("trynotepad.msi", msiOpenDatabaseModeReadOnly

The first parameter to OpenDatabase is simply the path to the package: the
actual MSI file. The second parameter says how you plan to use it. In this case,
the value zero means that you aren't planning to update the package.
You're going to do an inventory of the files in the package, so you'll be set-
ting up a SQL-like query into the File table that you previously looked at with
Orca. This works using the concept of a "view" based on a query. A View object
is returned by calling the OpenView method of the Database object, passing the
query that returns the data. The returned View object is a collection of records-
a dataset if you like.

25
Chapter 2

Dim view
Set view = database.OpenView
("SELECT 'FileName', 'Version', 'FileSize' FROM 'File''')

This query should look familiar if you've worked with databases. You're get-
ting items from the File table here; those items correspond to the column names
in the Orca view of the File table. Incidentally, look carefully at what the column
names are surrounded by. Those are grave characters, sometimes known as back
quotes or peck marks: ' . They are not single quotation marks. It is usually safer
to quote the database content items with grave characters to avoid conflicts
with reserved words.
The way you iterate through each of the records is to use the Fetch method
of the View object:

Dim record
Set record = view. Fetch

At this point you have a record: a row from the File table. You can retrieve
each of the columns with the StringData property of the Record object. You
retrieve a single item by indexing StringData with an index that corresponds to
its order in the original query, the SELECT statement. The query order was
FileName, Version, FileSize, so StringData(l) returns FileName, StringData(2)
returns Version, and StringData(3) the FileSize:

Dim afile
afile = record.StringData(l)

This gives you a string containing the FileName value of the particular
row. When all the Record objects in the View have been returned with
View.Fetch, the final returned Record object is empty, so the script can check to
see if the Record object has the value Nothing to find out whether all the records
have been returned. Putting this all together into a code fragment that loops
through the File table, you have this code:

Set view = database.OpenView


("SELECT 'FileName', 'Version', 'FileSize' FROM 'File''')
view. Execute
Do
Set record = view. Fetch
If record Is Nothing Then Exit Do
afile = record.StringData(l)
aversion = record.stringdata (2)
fsize = record.Stringdata (3)

26
Building an MSI File: Visual Studio and Orca

fullmsg = fullmsg &afile & " " &aversion & " " &fsize &vbcrlf
Loop
msgbox fullmsg

The principles of updating the package are similar. To make this updating
script a bit more interesting, it reads a text file consisting of a series of com-
mands that modify the database. You use FileSystemObject to read the
modify.txt file containing the commands:

Set fso = CreateObj ect (" Scripting. FileSystemObj ect")


Set afile = fso.GetFile("modify.txt")
set ts = afile.OpenAsTextStream (1, 0)

You create an Installer object and open the database package. However,
this time you're updating the package, so you open in transacted mode. This is
important when you close the database after your changes:

Const msiOpenDatabaseModeTransact = 1
Set database = installer.OpenDatabase
("trynotepad.msi", msiOpenDatabaseModeTransact)

Given a command that updates the database package, as in the previous


script you use the OpenView method of the Database object, passing the
command you expect to run. With this command in a string called
"thecommand" that you get by reading the text file, you do the OpenView:

Set view = database.OpenView(thecommand)

Because you're updating, these commands use verbs such as Update, Insert,
and Delete, so you use the Execute method of the View object to cause the
change to occur. Put this loop together to read the text file and execute the SQL
updates:

Dim thecommand, view


Do
thecommand = ts.readline
Set view = database.OpenView(thecommand) CheckError
view. Execute : CheckError
if ts.AtEndofStream then exit do
Loop

The modify.txt file supplied with the book samples has two updates. The
first inserts a new Property into the Notepad installation that you built. The text
of this command follows:

27
Chapter 2

INSERT INTO Property (Property. Property, Property. Value) VALUES


('ARPHELPLINK', .http://www.microsoft.com.)

Note that this is in two general pieces. The first names the table and the
columns into which data is being inserted in the form <table>.<column>. The
second part lists the values corresponding to those columns. In this example,
ARPHELPUNK is a standard Windows Installer property that is displayed in the
Add/Remove Programs applet as a "Click here for support information" link. VS's
installer doesn't let you specify one, so this example shows the way you add one
to point to Microsoft's Web site.
If you refer to Figure 2-9, you see an existing value for the property
FolderForm_AllUsers with a value of ME. Your second update changes the value
of that existing property in the property table from its previous ME to now
say ALL.

UPDATE Property SET Property. Value = 'ALL' WHERE Property. Property =


'FolderForm AllUsers'

When you opened the database, you opened it in transaction mode. This
means that none of the changes you've made are in the database package yet. To
save the updates, you must commit the changes with the Commit method of the
Database object:

database. Commit

Now that you've been introduced to an example of how to alter the content
of an installation package outside the VS environment, you may wonder about
the effect on the installation of changing this particular FolderForm_AllUsers
property. VS.NET generates this property-it's not a standard Windows Installer
one. What happens here is that the value of the FolderForm_AllUsers property
drives the state of the Everyone or Just me choice in the installation dialog
shown in Figure 2-3. After you change the property value from ME to ALL with
that Update statement, when you install the new package you'll note that the
radio button now defaults to Everyone. How did I know that ALL is a legal value
for the property value? You might have noticed that Orca has a Find choice
under the Edit menu. If you do this Find and put FolderForm_AllUsers in the
"Find what" text box, the search eventually shows you a ControlEvent table that
has an entry with a condition FolderForm_AllUsers="ALL" (see Figure 2-11).
I won't go into the deep details of dialog behavior here, but the FolderForm user
dialog (the one with those Everyone/Just me radio buttons) has a ControlEvent
that is triggered off the Next button of the dialog. This event occurs when the
user chooses the Next button, and the event sets the value of the ALLUSERS
property to 2 if FolderForm_AllUsers= "ALL". It's this value of the ALLUSERS

28
Building an MSI File: Visual Studio and Orca

property that determines whether the installation is for the current user or for
the system as a whole (meaning that the product is installed for all users of the
system).

_ . ItyNolt:pad m'.. , - Oren .' ~.

~ s~
Co_ O
No,a.."",, s~ 000I<C0aI o.r.<lIOIskSpo<ie°l
_n"" E""DIaIog Return f_"",,_NeaAtgo-- PH)
ConIralCondobo<> N""'Sun"" Ne.oOooIog IF_.F"",,_N F_"""_~<>- ANO
eor.""E_t N...s..n"" DoAc:bon frdlora_ro 1 ~
NCCl8ut.ton

_IOn
Cteotefolder SeITe .11> TARGET[)(R 1 0
CUs_
Ooolog OtokCostllulton ~ o.sIICoot I
Dwocto<y OtokCottSun"" SetTetgO<Path TARGET[)(R o
D<localOt Speo.....o..Jog SeIodFoidef{)t 1 1
DupIocotofie 8<o¥oM8uIton r_aIcIet
E""DIaIog
TARGET[)(R
_
o
Enwonmont 0K8utt0n o
Em>< ConceIlluIlOn E""OIoIog ~um 1
E--.v
Ext_
c-.............
CencelSuIlOn R_ 0

T_a7 ConttolEwnl • 88 I'CM'S 000I0g_ • SIringfn) K.y

Figure 2-11. ALLUSERS in the ControlEvent table

The ALLUSERS property is a Windows Installer property that you can set to
three states:

1. Unspecified (NULL is how the SDK documentation describes this) . The


installation defaults to a per-user installation.

2. A value of 1. This means a per-system installation, with the caveat that


the installation will fail if the user does not have administrative privi-
leges.

3. A value of 2. This causes a per-system installation if the user has admin-


istrative privileges, and a per-user installation if the user does not have
administrative privileges.

For now, I'll point out that the nondeterministic value of 2 is likely to be
unwelcome in some environments. In particular, it's unusual for applications to
be installed on servers for the installing user-it's much more likely that the
product is being installed for all users of the server. Having it accidentally
installed for the current user could be a disaster, so in the cases where you know
how the product is intended to be installed and used, force the issue by setting
the ALLUSERS property accordingly. You can do that in the ControlEvent table
in Figure 2-11 by changing the Argument value to 1 using Orca.

29
Chapter 2

Summary
You've looked at building a basic installation package and seen some of the con-
tents of the underlying database tables that are used during the installation.
You've had a brief look at Windows Installer properties and the APIs that you can
use to access database packages. One of the key points to take away from this
chapter is that a Windows Installer Component is the basic unit of an installa-
tion, and you'll come back to this idea many more times.

30
CHAPTER 3

COM in the Windows


Installer World
IN THIS CHAPTER, you'll build a package to install a COM server, but first some
background and history.

Let's All Share


You probably know that a COM object is created by a COM server in response
to-and on behalf of-a client request for a unique Classid and Interface ID.
Look at the specific case of a COM server implemented as a DLL. When
installed, this COM server has a Registry entry in HKCR\CLSID\{Classid
Guid} \InprocServer32 that usually contains the path to the server. (I say usually
because you'll see cases later in the book where InprocServer32 isn't the full
path to the DLL.) Consequently, every client that asks for this class causes
Windows to go to this unique Registry entry to find the path to load the server.
The process whereby these Registry entries are created initially is called
self-registration, "self" because the server itself contains the code to write these
Registry entries using an exported function called DllRegisterServer. Installation
has historically meant that the DLL first is copied to the system, and then its
DllRegisterServer entrypoint is called. This is how Regsvr32.exe registers a
server, although installation programs generated by proprietary software tools
don't usually run Regsvr32.exe-they typically just load the DLL, then use the
GetProcAddress Win32 API call to find the location of DllRegisterServer and call
it. (You can also have out-of-process COM servers implemented as executa-
bles-EXE files-that have a different installation scheme because they don't
export a DllRegisterServer function, but the general principle here is the same in
both cases.)
What happens if multiple products want to use the same COM server?
Clearly this is desirable because a COM component is most often used as a
shared component. If a product Pl installs the DLL to location A, and another
product P2 installs it later to location B, the DllRegisterServer for the later prod-
uct will clearly result in the InprocServer32 path now pointing to location B.
Three things are wrong with this scenario:

31
Chapter 3

1. The product P2 might have installed an older version of the DLL to


location B. Product PI now fails if it requires new interfaces imple-
mented in the DLL that the registration entries no longer refer to.

2. If product PI is uninstalled, it has no clue that someone else is using


the COM server, so it happily deletes the registration entries and breaks
productP2.

3. If product P2 is uninstalled, it uninstalls its Registry entries, and the


COM server and product PI are broken.

The way out of these dilemmas consists for the most part in making sure
that every client that uses the COM server arranges to install it to a specific
unique location on the system. Windows provides some help and a convention
by encouraging use of the Registry to count the references to shared DLLs. What
you'll examine here is the reference counting scheme that has historically been
used to manage the sharing of common files. I'll use it to show how sharing
schemes need to work.
When an installation program copies a DLL to the system, it looks in
HKLM\Software \Microsoft\ Windows \ CurrentVersion \SharedDLLs for the path
where the DLL is going to be installed. If the DLI.:s install path is in this Registry
location, the counter for that path is incremented. If it isn't there already, there
is usually an option in the installation development tool that causes the path to
be entered there with an initial count of one. When the product is uninstalled,
the reference count is decremented. When the count becomes zero, this means
that the DLL is no longer being used and it can be removed from the system.
The behavior you see at this point depends on the uninstall program. Some
might ask for confirmation that it's acceptable to remove the shared DLL that's
no longer in use. The key point is that removal of the actual DLL is also the trig-
ger that causes the registration entries to be removed as well. I should stress that
this SharedDLLs scheme is not the primary mechanism that Windows Installer
uses to count references to installer components, although it supports the
SharedDLLs mechanism.
Note that this reference counting scheme is based on the path to the DLL. If
a COM DLL is installed to the wrong location, the reference counting breaks. It
does no good to have the COM DLL with a reference count of one in two sepa-
rate paths in the SharedDLLs entries. Using the preceding example, you're still
in trouble if product PI has reference counted the DLL's path in one location
and product P2 in another because each believes it's the only remaining user of
the DLL and removes the Registry entries.
It's worth noting here that you can use this reference counting in any case
where a shared file is installed to a common location, not just COM server DLLs.

32
Another Random Scribd Document
with Unrelated Content
The Project Gutenberg eBook of The Horse and His
Rider
This ebook is for the use of anyone anywhere in the United States and
most other parts of the world at no cost and with almost no restrictions
whatsoever. You may copy it, give it away or re-use it under the terms of
the Project Gutenberg License included with this ebook or online at
www.gutenberg.org. If you are not located in the United States, you will
have to check the laws of the country where you are located before using
this eBook.

Title: The Horse and His Rider

Author: Sir Francis Bond Head

Release date: August 17, 2020 [eBook #62959]


Most recently updated: October 18, 2024

Language: English

Credits: Produced by Julia Miller, Jana Palkova and the Online


Distributed Proofreading Team at https://www.pgdp.net (This
file was produced from images generously made available
by The Internet Archive/American Libraries.)

*** START OF THE PROJECT GUTENBERG EBOOK THE HORSE AND HIS
RIDER ***
THE HORSE AND HIS RIDER.
By SIR FRANCIS B. HEAD, Bart.
WORKS BY SIR FRANCIS HEAD.
ROUGH NOTES OF JOURNEYS ACROSS THE PAMPAS
AND OVER THE ANDES. Post 8vo. 2s. 6d.

"None of Sir Francis Head's works have achieved a greater popularity than
his Gallop across the Pampas. Written thoroughly con amore, and with
the easy flow of ideas that seem, like their originator, to be swinging
along at a hand-gallop, he carries us away with him over the boundless
plains of South America, free and untrammelled as himself."—Frazer's
Magazine, Jan. 1861.

DESCRIPTIVE ESSAYS. 2 Vols. Post 8vo. 18s.


BUBBLES FROM THE BRUNNEN OF NASSAU. By an Old Man. 16mo. 5s.
THE EMIGRANT. Fcap. 8vo. 2s. 6d.
STOKERS AND POKERS; or, the London and North-Western Railway. Post
8vo. 2s. 6d.
DEFENCELESS STATE OF GREAT BRITAIN. Post 8vo. 12s.
A FAGGOT OF FRENCH STICKS. 2 Vols. Post 8vo. 12s.
A FORTNIGHT IN IRELAND. Map. 8vo. 12s.

"Sir Francis Head's works are now so well known to the British public that
it is almost superfluous to criticise their merits or their style.
"His descriptions remind us of Hogarth. There is the same minute
attention to details, the same truthfulness of outline, the same
undercurrent of humour."—Frazer's Magazine, Jan. 1861.

JOHN MURRAY, ALBEMARLE STREET.

LONDON: PRINTED BY W. CLOWES AND SONS, STAMFORD STREET,


AND CHARING CROSS.
the hounds are LATE to-day!
FRONTISPIECE

THE HORSE AND HIS RIDER.


By SIR FRANCIS B. HEAD, Bart.
He grew unto his seat;
And to such wond'rous doing brought his horse,
As he had been incorps'd and demy-natur'd
With the brave beast.
Hamlet, Act iv. Scene 7.
SECOND EDITION.
LONDON:
JOHN MURRAY, ALBEMARLE STREET.
1861.
The right of Translation is reserved.
PREFACE.

The writer of this little volume deems it only fair to forewarn his readers that
he is not, and never has been, an inhabitant of that variegated region in
creation commonly called "the sporting world."
He has never bred, raced, steeple-chased, nor betted sixpence on any colt,
filly, horse, or mare. He has never seen, nor been seen by, the Jockey-Club.
He has never been on the turf. He does not belong to "the ring."
Nevertheless, sometimes in the performance of public duties,—sometimes
from private inclination,—sometimes for the benefit of his health,—sometimes
for recreation,—sometimes for rumination,—sometimes to risk his life,—and
more than once to save it, he has, throughout a long and chequered career,
had to do an amount of rough-riding, a little larger than has fallen to the lot of
many men.
His observations and reflections on horses and horsemen he now ventures to
submit to that portion only of the community who, like himself, preferring a
long tether to a short one, take exercise on four legs, instead of on two.
CONTENTS.

Page
Preface 3
Contents 5
Preliminary Observations—The Horse 7
Mr. Rarey's mode of subduing Horses—compared with that practised in South
America 16
Difference between the character and conduct of a wild horse and a tame one 24
Horsemanship—a just seat—a light hand—their advantages in riding, in
leaping, in galloping over rough ground, in going fast down hill, in falling 28
A jump into a stone-quarry—the Mameluke's leap out of the Citadel of Cairo
—Letter from Gen. Moore, and story of his fall on horseback over a
precipice of 237 feet 44
Mode of riding at Timber 51
Water Jumping—Scene at a Northamptonshire brook 54
Different ways of Swimming a Horse 62
Judicious Riding 63
Use and Abuse of Spurs 65
How to treat a Hunter in the Field 74
How to bring a Hunter Home 80
How to Dress for Hunting 89
How to Eat and Drink for Hunting 97
Difference between Leicestershire and Surrey Hunting 104
The Stable 106
On Shoeing 114
On Roughing Horses 119
Saddles 121
Bridles 126
Intrinsic Value of a Horse 130
On Shying 132
On Singeing 136
Meet of the Pytchley Hounds at Arthingworth to draw Waterloo Gorse 143
Effects created by the Sight of Hounds on Horses, Men, Women, Children,
Sheep, Lambs 152
Cruelty of Hunting Considered 159
The Lamb and the Fox 163
Beneficial Results, social and pecuniary, of Hunting 167
Sketch of the Life and Death of Thomas Assheton Smith 173
On Military Horse-power 195
On Hobbling and Anchoring Cavalry Horses 206
On Chloroforming Horses 215

MAN AND HIS RIDER.


mode, in northern parts of south america, of riding over the andes,
on A RED INDIAN.
query, which is "THE SAVAGE?"
To face page 7.
THE HORSE AND HIS RIDER.
The Horse.
In almost every region of the globe, not only on its surface, but at different
depths beneath it, the history of the horse is recorded.

"Fossil remains," says Colonel Hamilton Smith in the twelfth volume of the
Naturalist's Library, "of the horse have been found in nearly every part of
the world. His teeth lie in the Polar ice along with the bones of the
Siberian mammoth; in the Himalaya mountains with lost, and but recently
obtained, genera; in the caverns of Ireland; and, in one instance, from
Barbary, completely fossilized. His bones, accompanied by those of the
elephant, rhinoceros, tiger, and hyæna, rest by thousands in the caves in
Constadt; in Sevion at Argenteuil with those of the mastodon; in Val
d'Arno and on the borders of the Rhine with colossal urus."

But what is most deserving of attention is that while all the other genera and
species, found under the same conditions, have either ceased to exist, or have
removed to higher temperatures, the horse alone has remained to the present
time in the same regions, without, it would appear, any protracted
interruption; fragments of his skeleton continuing to be traced upwards, in
successive formations, to the present surface of the earth—the land we live in.
In like manner in history, sacred, profane, and modern, the horse is to be
found omnipresent, sharing in the conquests, in the defeats, in the prosperity,
in the adversity, in the joys, in the sorrows, in the occupations, and in the
amusements of man.
In Genesis xlvii. 17, Moses records that the Egyptians (1729 years before
Christ), at a time when the famine was sore in the land of Canaan, gave to
Joseph their horses in exchange for bread.
Two hundred and thirty-eight years afterwards (1491 b.c.), six hundred chosen
chariots for nobles and generals, all the war chariots of Egypt armed with iron
to break the enemy's battalions, the horsemen, and all the host of Pharaoh, in
their pursuit of the children of Israel, were overthrown in the midst of the Red
Sea, so that there remained not so much as one of them.—(Exodus, chap.
xiv.)
"Then sang Moses and the children of Israel this song unto the Lord, and
spake, saying, I will sing unto the Lord, for he has triumphed gloriously:
the horse and his rider hath he thrown into the sea."—Exodus, chap. xv.

The Canaanites whom Joshua engaged at the waters of Merom had cavalry,
and a multitude of chariots drawn by horses. Sisera, general of Jabin, King of
Hazor, had 900 chariots of iron. Judah could not get possession of the lands
because the ancient inhabitants of the country were strong in chariots of iron.
The Philistines, in their war against Saul, had 30,000 chariots and 6000
horsemen. David having taken 1000 chariots of war from Hadadezer, King of
Syria, hamstrung the horses, and burned 900 chariots. During the latter
periods of the Jewish monarchy Palestine abounded in horses.
In 1 Kings, chap, iv., it is stated that Solomon had 40,000 stalls of horses for
his chariots, and 12,000 horsemen.
Cyntacus, a King of Ethiopia, entered Egypt at the head of 100,000 cavalry;
and from that period to Balaklava, and from it to the last battle in modern
history, horses in greater or less numbers have shared in the dangers of war.
In many instances the history of an individual horse forms part and parcel of
the history of his rider: accordingly we learn that Bucephalus (so called
because his head resembled that of a bull, Βου κεφαλος), when thirty years
old, saved the life of Alexander the Great, who, in remembrance, built a city
which he called after his name.
We are, moreover, taught in our schools, that the Emperor C. Caligula, as an
especial honour to his favourite horse, not only created him a high-priest and
consul, but caused him to live in marble apartments, in which he stalked
about adorned with the most valuable trappings and pearls the Roman empire
could supply.
In statuary, ancient as well as modern, the horse lives with his rider.
On the frieze of the Temple of Minerva, in the Acropolis of Athens, at Nineveh,
and numerous other localities, are to be seen sculptured or painted, more or
less beautifully, ancient figures of men on horseback.
In all the great cities of Europe the horse and his rider, or rather the rider and
his horse, are ornaments deemed worthy to occupy conspicuous positions in
the most important thoroughfares. Accordingly in London, within a few
hundred yards of each other, are to be seen equestrian statues of Kings
Charles I., William III., George III., and George IV.
Mounted on one charger, the Duke of Wellington in his cocked hat and
feathers, military cloak, sword, pistols and spurs, in all weathers, rides
triumphantly on the summit of an arch at the western end of London, while,
at the same moment, in pantaloons and shoes, without hat, stirrups, or spurs,
mounted on another charger, he appears, as a sentinel, in front of the Bank of
England, the commercial heart of the empire.
Among the great potentates of the earth, the coin that is most currently used,
in proffers to each other of amity and friendship, is a horse. And accordingly,
the Beys of Tunis, of Algiers, and Egypt; every sovereign in Europe, including
the Czar of Russia, and the Sultan of the Turks; the Emperor of Morocco, the
Kings of Persia and Abyssinia, and other rulers of smaller name, have
transmitted to the Queen of Great Britain, with due compliments, specimens
of their finest horses.
In the Life of Bruce, the Abyssinian traveller, it is recorded that Fasil, after
having assembled the leaders of the Galla tribes, said to the noble Briton,
"Now, before all these men, ask me any thing you have at heart, and be it
what it may, they know I cannot deny it to you!" Bruce, of course, asked to be
conducted immediately to the head of the Nile. Fasil then turned to his seven
chiefs, who got up. They all stood round in a circle and raised the palms of
their hands, while he and the Galla with great apparent devotion repeated
together a prayer, about a minute long. "Now," says Fasil, "go in peace: you
are a Galla. This is a curse upon them and their children, their corn, grass,
and cattle, if ever they lift their hand against you or yours, or do not defend
you to the utmost, if attacked by others." Upon this, Bruce offered to kiss his
hand, and they all went to the door of the tent, where there stood a very
handsome grey horse. "Take this horse," said Fasil, "as a present from me. But
do not mount it yourself. Drive it before you, saddled and bridled as it is. No
man of Maitsha will touch you when he sees that horse,"—which proved a
magician that led him towards his object—an Ægis that shielded him on his
way.
In like manner to the people of France, the 'Moniteur' has just officially made
the two following announcements:—

"Algiers, 19th September, 1860.


"The Emperor and Empress yesterday morning laid the first stone of the
fine boulevard which is to run along the shore. An immense concourse of
persons, both French and native, were collected, eager to see their
Majesties, and the ceremony displayed a most picturesque character.
Under the skilful direction of General Jusuf, contingents of the Kabyle
infantry and cavalry of the three provinces, with all the Aghas and Caids
at their head, had been assembled to come and pay homage to the
Emperor. After a sham fight between the different tribes a grand fantasia
took place by from 9000 to 10,000 horsemen rushing forward at the
swiftest gallop, and discharging their firearms before their Majesties' tent;
afterwards a magnificent charge was given by twelve squadrons of
Spahis, crossing the plain like a hurricane; then followed tilting matches,
gazelle, ostrich, and falcon hunts; a grand filing-off of the Touaregs, with
their faces veiled, and mounted on their camels; and of the Chambaas,
those inhabitants of the depths of the Desert, and the future carriers of
French commerce into the Soudan. After, in short, one of the most
splendid spectacles that could be imagined, all the Goums, forming an
immense line of battle, advanced majestically, with banners displayed and
muskets held high in the air, towards the eminence on which the
Emperor's tent had been pitched. The chiefs, clad in the richest burnous,
alighted from their steeds and came in a body to present the horse of
homage, caparisoned with gold, and thus perform an act of submission to
the Sovereign of France. At this moment, rendered solemn by the beauty
of the scene and the warlike appearance of the various tribes whose long
resistance has given glory to the French arms, the Emperor could not
prevent himself from giving way to visible emotion. The Bey of Tunis was
present at this grand solemnity."

"Paris, 28th September, 1860.


"General Count Pierre Schouvaloff, Grand Master of Police at St.
Petersburg, and his brother, Count Paul Schouvaloff, both aides-de-camp
to the Emperor of Russia, were received the day before yesterday by the
Emperor Napoleon, and had the honour of presenting to his Majesty four
horses, sent as a present by the Emperor Alexander. These fine animals,
which have been accompanied to Paris by a veterinary surgeon, four
hussars, and a non-commissioned officer of the Imperial Guard, are of the
celebrated Orloff race, and come from the Imperial breeding stud at
Chrenovsky. They were selected from among a great number by the Czar
himself; and during the two mouths that their journey from the very heart
of Russia has occupied, they have been the objects of the greatest care.
His Majesty greatly admired the beauty, strength, and symmetry of the
horses, and expressed to the Counts Schouvaloff how gratified he felt at a
mark of attention which showed the friendly relations existing between
the two Sovereigns."
In war, the value of these noble animals to man is well described by
Shakspeare's thrilling exclamation of King Richard—
"A horse! a horse! my kingdom for a horse!"
In like manner, in civil life, how often has the schoolboy, who in his infancy
had clutched with ecstasy his toy—a little spotted horse on wheels—felt that
he would give his birthright for a pony!
On his arriving at Oxford or Cambridge, how often has the undergraduate, for
the professed purposes of application and recreation, submitted to his parents
or guardians a supplication for those three stereotyped wants of college life,
"a little money, a private tutor, and a horse!" Afterwards, in his manhood, and
even in his old age, how often has the Prime Minister of England, during a
most important debate, risen from his seat in Parliament to propose to the
legion of senators around him "that this House shall adjourn from Tuesday to
Thursday," for the well known object (acknowledged by "loud and protracted
cheering") of enabling himself, those who surround him, and everybody else,
"to go to the Derby," to purchase "Dorling's correct card of the names of the
horses, and the colours of their riders!"

Among our leading statesmen, how many, as patrons of the turf, have
purchased for several thousand guineas—a horse! How many, including Pitt,
Fox, Lord Althorp, Lord Derby, Lord Palmerston, Sir Francis Burdett, &c., &c.,
have been ardent followers of hounds!
Her Majesty Queen Victoria and the Emperor Napoleon III. each keep a pack
of stag-hounds; the Prince Consort, a pack of harriers. During the Peninsular
war, and again while commanding the army of occupation in France, the Duke
of Wellington, besides fighting and writing, maintained either a pack of fox-
hounds or boar-hounds.[A] George III. was strongly attached to hunting; his
great grandson, the Prince of Wales, "loves it better still."
In all our streets, in our fields, in our highways and bye-ways, along the
surface of merry England, and across it; under ground in coal-mines; revolving
in a mill;—in short, in every direction, and wherever we go, we see before us
—sometimes as man's companion, sometimes as his servant, sometimes as
his slave, and occasionally as his master—the horse, respecting which and his
rider we will now, without further preamble, venture to offer to our readers
the few following remarks.
[A] About 44 years ago a Frenchwoman, the proprietor of a small farm,
showed us, as a great curiosity, a "billet de logement" which had been
inflicted upon her, of which the following is a translated copy:—

"The widow —— will lodge for one night fifty-four dogs." [The Duke of
Wellington's hounds just arrived from England.]

(Signed) ——,
"Mayor."

"Imaginez-vous donc," exclaimed the poor old lady, uplifting her eyes and
the palms of both hands; "Imaginez-vous donc—cinquante-quatre chiens!!"
Mr. Rarey's Mode of Subduing Horses.
It is a singular fact, that although England produces the finest horses in the
world, and though the English people have always fancied they understood
their management better than any other nation, yet, lately, not only have we
all been astonished by the superior knowledge on this subject of a trans-
Atlantic cousin, but what is still more surprising, our sporting men have rushed
forwards to pay to Mr. Rarey no less a sum than about 15,000l. for exhibiting
to them a system of horse-breaking, the philosophy of which is based upon a
few simple facts, which, although unreflected on, have ever been lying close
before our eyes.
Of all animals in creation, there is no one we should all of us be so very sorry
to lose as the horse. In peace and in war, on burning sands under the equator,
or on eternal snow in the frigid zone, for pleasure or for business, well fed or
starving, he is always not only ready, but eager, to the utmost of his strength,
to serve a master, but too often inconsiderate, ungrateful to him, and unjust.
As soon as his courage is excited, no fall, bruise, blow, or wound, that does
not paralyse the mechanism of his limbs, will stop him; indeed, with his upper
and lower jaw shot away, and with the skin dangling in ribands, we have seen
him cantering, apparently careless and unconscious of his state, alongside of
the horse artillery gun from which he had just been cut adrift.
But although in the hunting-field, on the race-course, or in harness, a horse
will generally, from sheer pluck, go till he drops, yet, whenever he encounters
physical strength greater than his own, our hero all of a sudden acts like an
arrant coward.
For instance, in the mail, it apparently matters not to the spirit of the horses
whether there be one passenger or six—light bags or heavy ones; on the
contrary, the greater the weight, the more eagerly do they strain to force it to
follow them. The faster they are allowed to go, the harder do they pull, until,
if the reins were to break, they would enjoy the opportunity by running away,
not as in the days of Phaeton with the chariot of the sun, but with say a ton
and a half, of they know not what, at their heels. And yet, if on the following
day the same high-flying, high-spirited, high-mettled horses were to be
hooked to a sturdy living oak tree, after two or three ineffectual snatches to
move it, no amount of punishment would be sufficient to induce them to go to
the end of their traces; in short, to use a well-known expression, they would
all "jib." Again, if a horse in harness, however resolutely he may be
proceeding, slips upon pavement, and falls heavily on his side, after vainly
making three or four violent struggles to rise, he becomes all of a sudden so
completely cowed, that not only without any resistance does he allow his
harness piecemeal to be unbuckled, the carriage detached, and pushed away
far behind him, but, when lying thus perfectly unfettered, it requires kicks,
stripes, and a malediction or two, to induce him to make the little effort
necessary to rise from his prostrate state.
Again, in the hunting-field, a noble, high-couraged horse, a rusher at any
description of fence, the very sight of which seems to inflame his ardour, in
most gallant style charges a brook, which when he is in the air he sees is too
broad to be cleared. On his chest striking against the bank, and while his rider,
delighted at feeling that he is not a bit hurt, is luxuriously rolling over and over
on the green grass like a rabbit that at full speed has been shot dead, this
gallant steed makes two, three, or four desperate efforts to get to him; and
yet, simply because the mud at the bottom of the brook catches hold of his
hind feet, and the sticky perpendicular clay bank grasps his fore ones, his
courage suddenly fails him, and as nothing will then induce him to make
another effort, it becomes necessary to send, often several miles, for cart-
horses to drag this high-bred animal out by his neck.
But although this strange mixture of courage and cowardice appears to us at
first to be inexplicable, yet on reflection we must perceive that it is in strict
accordance with the beneficent decree that "man should have dominion over
every beast of the field."
The weight and muscular strength of a horse multiplied into each other, form
a momentum which, if his courage were as indomitable as that of man, would
make him the master instead of the servant of the human race; and
accordingly, although, for all the purposes for which man can require them,
his energy and endurance are invincible, yet, to ensure his subjection, his
courage has been so curiously constituted, that, as it were, by touching the
small secret spring of a safety valve, the whole of it instantly evaporates; and
although Mr. Rarey has not exactly explained this theory, he has, with
extraordinary intelligence and success, reduced it to practice as follows:—
When a horse of a sensitive and sensible disposition is placed under the care
of a man of weak nerves, he very soon finds out that, by the help of his body,
teeth, and heels, that is to say by squeezing, crushing, biting, and kicking his
groom, he is able to frighten him; and no sooner is this victory attained, than
the tyrant begins to misbehave himself to everybody in every possible way,
until, as in the case of Cruiser, it is declared dangerous to approach him, even
with food; that no man can ride him; in fact, that he is an animal beautiful to
look at, but thoroughly useless to mankind.
Now, to cure this disorder, the wild beast, for such he is, with great
precaution, by several guy-ropes, is led close to the wheel of a waggon, under
which Mr. Rarey, putting his hands through the spokes, manages to lift up and
gently strap up one fore-leg, and to affix a long strap to the fetlock of the
other, which two simple operations at once ensure the victory he is about to
attain.
As it gives a horse not the slightest pain or inconvenience to stand for a short
time on one fore-leg, Cruiser, while "amazed he stares around," is scarcely
aware that he is doing so; and as he is totally unconscious of the existence of
the other strap, he is perfectly astounded to find that no sooner does he
attempt to resent Mr. Rarey's bold approach and grasp, than, apparently by
the irresistible power of man, he is suddenly deprived of the use of both his
fore-legs.
The longer and the more violently he can be encouraged to resist, the more
deathlike will be the trance in which he is about to lie. He struggles—struggles
—struggles—until, as in the three instances we have described, his courage all
at once evaporates, and with heaving flank, panting nostrils, palpitating heart,
flabby muscles, and the perspiration bursting through every pore in the skin,
he then allows his conqueror to sit on his ribs, to fiddle in his ears, drum to
the gaping and gasping audience: in short, as the Duke of Wellington
described Lord Ellenborough's proclamation about the gates of Sumnauth, to
sing over his carcase "a song of triumph." And thus as Achilles was mortally
wounded in the only vulnerable part of his body—the heel,—so does Cruiser
find that in a heart which had never before failed him, and which had been
the terror of all who approached him, there exists a weak point, discovered by
Mr. Rarey, which has caused his complete subjection to man.
"Is this the face that faced ten thousand men,
And was at last out-faced by Bolingbroke?"
In old times this conversion of the bully into the coward could only be
effected, at great risk, by courage and physical force, as follows:—
Some years ago Captain ——, the well-known steeple-chase rider, bought at
Tattersall's, for a very small sum, a magnificent horse that no stranger in the
yard dared approach, and which therefore was "put up" and honestly sold as a
"man-killer."
On these propensities being explained by the purchaser to his head groom,
the resolute fellow bluntly replied that he would not at all object to take care
of the beast provided he were allowed, "in self-defence, to kill or cure him;"
and accordingly, as soon as the homicide entered his stable, with a steady
step, but avoiding looking into his eye, he walked up to him, and then, not
waiting for a declaration of war, but with a short, heavy bludgeon, striking the
inside of his knees, he knocked his fore legs from under him, and the instant
he fell, belaboured his head and body until the savage proprietor of both
became so completely terrified, that he ever afterwards seemed almost to
quail whenever his conqueror walked up to him.
Now, on comparing the two opposite systems, humane and inhuman,
scientific and unscientific, just described, it must be apparent to everybody,
that while for the latter a powerful hero must be procured, all that is requisite
for the former is calmness, gentleness, and two little straps which, in a lower
stratum, physically fight a desperate battle, above which man morally and
serenely presides; the horse, nevertheless, all the while ascribing to him alone
the whole credit of the victory eventually attained.
Under the ordinary process used by horse-breakers, it requires several weeks
before a colt—often broken down as well as in by the operation—surrenders
his own will to that of his rider, whereas Mr. Rarey has not only in public
repeatedly demonstrated, but many who have followed his prescription have
testified, that a young thorough-bred horse, perfectly unbroken, can, in the
course of about half-an-hour, be so thoroughly conquered by the two straps
which he conceives to be part and parcel of the irresistible strength of his
master, that so soon as he is satisfied that his own powers of resistance are of
no avail, he subserviently allows himself to be bridled, saddled, mounted, and
ridden.
The principle of Mr. Rarey's system of domination is at this moment curiously
exemplified in the little dairy farm-yard of Mr. Roff, residing on the Brighton
road, near Croydon.
Some months ago, on approaching these premises, we observed a lot of
children playing with a yearling colt, who, to our surprise, was allowing them
to crawl between his legs and fondle him in various ways, just as if he were a
dog. On riding into the yard to inquire by what magical means the little
quadruped had been made so gentle and tame, we were informed by the old
farmer who owned him that his wife, kind to all her beasts,—
"She milk'd the dun cow that ne'er offer'd to stir:
Though wicked to all, it was gentle to her,"—
had for many years been yearning to add to them a pet colt; that accordingly
he had lately bought her one, and that she had tamed it: with uxorious pride
he added "she could tame anything." As, however, we were perfectly
convinced that his good wife, in spite of her comely, honest face, could not
fascinate a horse's heart quite as easily as a husband's, we cross-questioned
the latter for a considerable time, until he at last mentioned (as if it had
nothing whatever to do with the subject) that when he purchased the yearling
(whose mother had just died), not knowing how to bring it to his wife, with
the assistance of one or two men he strapped together all its four feet, and
then, lifting it into his cart, just as if it had been a calf, he trotted away with it,
jolting it and jumbling it till he reached his home, where he uncarted it, and,
in due time, with his own hands, restored to it the use of its limbs.
Of course this was a much stronger dose of discipline and subjection than Mr.
Rarey has ever found necessary to administer, even to Cruiser; and there can
exist no doubt it was this cooling medicine, this soothing mixture, which had
produced the strange and salutary effects that had attracted us into the little
yard. And thus, in every region of the globe, not only colts and horses, but all
living animals, man especially included, surrender at discretion to any
authority which, after a fruitless struggle—such a one for instance as induced
Napoleon I., on the 15th of July, 1815, to seek for refuge on board H. M. ship
Bellerophon from the allied armies of Europe—they find it to be utterly
impossible to resist.

The differences between the character and conduct of a wild horse and a
tame one are, we believe, not very clearly understood. It is generally
conceived that in the difficulty of adhering, technically termed sticking to the
back of a horse, there exist three degrees of comparison, namely:—
1. That it is rather difficult to ride a horse that has been broken in.
2. That it is exceedingly difficult to ride one that has been petted, patted,
bitted, lounged, but not mounted.
3. That it must be almost impossible to mount and ride a wild horse just
caught, that has never been touched by a human hand.
We will, however, humbly venture to assert that, in certain instances, the
three steps of this little ladder might be reversed.
1. In a state of nature the horse is such a zealous advocate of our popular
principle of "self-government," he is so desirous to maintain his
"independence," that although he will allow almost any quadruped, even
wolves and lions, to approach within a certain distance, yet the moment he
sees a man, though on horseback, he instinctively turns his tail towards him,
and, when followed, gallops away.
If, consequently, by the triumph of reason over instinct he be caught, or rather
by the lasso tumbled head over heels, saddled, and if all of a sudden, to his
vast astonishment, he finds sitting astride his back, with a cigar in his mouth,
the very human being he has always been avoiding, his first and almost only
feeling is that of fear; and accordingly, if he be retained by the bridle,
instantaneously, by a series of jumps on all four legs, he makes impromptu his
first hurried, untaught, unpractised effort to dislocate a rider. But if, instead of
being as it were invited to perform these unsophisticated antics, he be
allowed, or rather, by whip and severe spurs, be propelled to do what he most
ardently desires, namely, run away, his power of resistance is over, and his
subjection inevitable. For at the top of his speed, just as when swimming, a
horse can neither rear, kick, nor plunge, and therefore at his best pace he
proceeds on his sure road to ruin, until not only all his wind is pumped out of
him, but after that, until twisted hide-thong and sharp iron have converted his
terror of man into an ardent desire to be obedient to his will. In fact, like a
small nation that has unsuccessfully been contending against a great one, he
wishes to put an end to the horrors of war, and to sue for the blessings of
peace.
2. If a domestic horse that has been handled, fondled, but never ridden, be
suddenly saddled and mounted, the rider has greater difficulties to encounter
than those just described: for the animal is not only gifted by nature with all
the propensities of the wild horse to reject man, but, from being better fed, he
has greater strength to indulge in them; besides which he enjoys the immense
advantage of being in a civilized, or, in plainer terms, an enclosed country.
Accordingly, instead of being forced to run away, his rider is particularly afraid
lest he should do so, simply because he knows that the remedy which would
cure the wild horse, would probably kill him. In fact, the difference to the rider
between an open and an enclosed field of battle is exactly that which a naval
officer feels in scudding in a gale of wind out of sight of land, and in being
caught among sandbanks and rocks in a narrow channel.
3. Of all descriptions of horses, wild and tame, by far the most difficult to ride
is that young British thorough-bred colt of two or three years old that has
been regularly "broken in" by himself, without giving the slightest warning, to
jump away sideways, spin round, and at the same moment kick off his rider.
The feat is a beautiful and well-arranged combination of nature and of art.
Like the pugilistic champion of England—Tom Sayers—he is a professional
performer, gifted with so much strength and activity, and skilful in so many
quick, artful tricks and dodges, that any country practitioner who comes to
deal with him is no sooner up than down, to rise from his mother earth with a
vague, bewildered, incoherent idea as to what had befallen him, or "how he
got there."
If a horse of this description and a wild one were to be mounted
simultaneously, each by an equally good rider, in an unenclosed, uncultivated
region, both the quadrupeds probably at the same moment would be seen to
run away: the Briton for ever, to gain his liberty; the other quadruped, just as
surely, to lose it!
Having now sufficiently discussed the character and conduct of the horse, we
will presume to offer, or rather to bequeath to our readers, a very few
observations as regards his rider.
Seat on a Horse.
The best position of a man on horseback is, of course, that which is most
agreeable to both animals, and which, from its ease and flexibility, as they
skim together over the surface of the earth, apparently combines them into
one.
Like everything in Nature, the variety of seats is infinite. They may, however,
generically be divided into two classes:
1. In the great plains of South America, in which it may truly be stated that for
every male inhabitant above five or six years of age Nature maintains at no
cost, no tax, and at no trouble to him, a stud of horses whose number is
legion, the rider sits almost perpendicularly, with the great toe of each foot
resting very lightly on, and often merely touching its small triangular stirrup,
his legs grasping the horse's sides slightly or tightly, as prosperous or adverse
circumstances may require.
In this attitude, which may be said to be that of standing astride over rather
than sitting upon the saddle, the pivot upon which the rider, gracefully
bending his body with a ball and socket movement, turns—in throwing his
lasso, in thrusting his lance forwards on either side, or in looking behind him—
is what is termed by sporting men his "fork."
In the few instances where pistols are carried, they are affixed behind the
right thigh, firstly, that in the common occurrence of the horse falling in his
gallop, they may not prevent the rider from rolling clear away from him; and,
secondly, because in that position the weapons are close to the rider's right
hand, which, as he flies along, is to be seen always dangling just above the
but ends, ready to grasp them the instant they are required.
This attitude is not only highly picturesque, but particularly easy to the rider,
who, while partaking of the undulating motion of his horse, can rest his
wearied body by slight imperceptible changes of position on the pivot or
"fork," on which, like corn waving in the wind, it bends.
The British cavalry sit astride above their saddles very nearly in this attitude,
which, as we have just explained, enables them with great facility to cut, or
give point in front, right or left, at cavalry or at infantry; and if they were not
embarrassed by their clothing, as well as by their accoutrements, and if, as in
the region to which we have alluded, they were to use no pace but the gallop,
each would soon become, or rather he could not help apparently becoming,
part and parcel of his horse. But our gallant men, although they have been
subjected to innumerable experimental changes of dress, &c., continue not
only hampered and imperilled by a hard cloak, holsters, and carbine affixed in
front of their thighs, and imprisoned, especially round their necks, within tight
clothing, but their travelling pace, the trot (a jolting movement unknown and
unheard of in the plains of South America), gives to their body and limbs a
rigidity painful to look at, and in long journeys wearisome to man and horse.
Indeed in the French cavalry, and occasionally in our own, the manner in
which the soldier, in not a bad attitude, is seen hopping high into the air, on
and off his saddle, as his horse, at apparently a different rate, trots beneath
him, forms as ridiculous a caricature of the art of riding as the pencil of our
Punch's "Leech" could possibly delineate.
2. Throughout the United Kingdom, civilians of all classes, gentlemen,
farmers, and yeomen, especially those who occasionally follow the hounds,
adopt what is commonly called "the hunting seat," in which, instead of "the
fork," the knees form the pivot, or rather hinge, the legs beneath them the
grasp, while the thighs, like the pastern of a horse, enable the body above to
rise and fall as lightly as a carriage on its springs.
In this attitude the rider cannot turn his body to the right or left, or look
behind him as easily as he could revolve upon his "fork."
For rough riding, however, of every description, the hunting seat, though
infinitely less graceful, is superior to that of the cavalry of Europe, for the
following reasons:—
One of the most usual devices by which a horse endeavours to, and but too
often succeeds in dislodging his rider, is by giving to his back, by a sudden
kick, a jerk upwards, which, of course, forces in the same direction towards
the sky that nameless portion of humanity which was partly resting on it, and
which in the cavalry cannot possibly get very far away from it.
But, in the hunting seat, the instant the rider expects such a kick, by merely
rising in his stirrups he at once raises or abstracts from the saddle the point
his enemy intends to attack, and accordingly the blow aimed at it fails to
reach it.
Again, on approaching a large fence, by the same simple precaution, the rider
entirely avoids the concussion of that sudden jerk or effort necessary to
enable the horse to clear it. In a fall, the pommel of the saddle and the
horse's neck and head are much easier cleared by short stirrup-leathers than
by long ones. Lastly, in a common trot, the former soften the jolt, which the
latter cannot easily avoid. In short, in a hunting seat, the rider, to his great
comfort and relief, rests more or less on his saddle as long as he likes, and
yet, the instant he anticipates a blow from it, leaves it, without metaphor ...
behind him.
Of horsemanship it may truly be said, that about four-fifths of the art depend
on attaining a just seat, and one-fifth on possessing a pair of light hands.[B]
But although the attainment of these advantages is not incompatible with an
easy, erect position on horseback, the generality of riders are but too apt to sit
on their horses in the bent attitude of the last paroxysm or exertion which
helped them into the saddle. Now, when a man in this toad-like position rides
along—say a macadamized road—he travels always ready, at a moment's
notice, to proceed by himself in the direction in which he is pointing, in case
the progress of his horse should be suddenly stopped by his falling down.
Indeed, when a horse, without falling down, recovers by a violent struggle
from a bad trip, a heavy rider in this attitude (called by Sir Bellingham Graham
"a wash-ball seat") is very liable to shoot forwards over his head in a parabolic
curve, ending in a concussion of his brain or in the dislocation of his neck,—
the horse standing by his motionless body perfectly uninjured.
On the other hand, when a man sits upright, justly balanced on his saddle,
any sudden jerk or movement forwards throws his shoulders backwards. If
therefore, while proceeding in that position, the horse thinks proper to fall, the
animal in the first instance is the sole sufferer. He cuts his forehead, hurts his
nose, breaks his knees, bruises his chest, while his head, neck, fore-legs, and
the forepart of his body, forced into each other like the joints of a telescope,
form a buffer, preventing the concussion the horse has received, from injuring,
in the smallest degree, the rider, or even the watch in his pocket, which,
without being ejected from the saddle, goes ticking, ticking, ticking on, just as
merrily as if nothing had happened. If he only trips, a rider poised justly in his
saddle can easily recover him.
A horse will not only refrain from treading upon any creature lying on the
ground, but in hunting he will make the utmost possible effort to avoid putting
a foot upon his master whenever
"On the bare earth exposed he lies."
If, however, his owner, from a bad seat or from false precaution, has suddenly
thrown himself from his back, it is often impossible for the animal, while
struggling to recover from a desperate trip, to avoid either trampling upon or
violently striking him.
For this reason a rider should never abandon his saddle so long as his horse
beneath it has a leg, or an infinitesimal part of one, to stand on. But so soon
as his downfall is announced by that heavy, thundering concussion against the
ground, the meaning of which it is impossible to mistake, the partnership
should instantaneously be dissolved by the horseman rolling, if possible, out of
harm's way.
But it occasionally happens not only that the horse rolls too, but that the
larger roller overtakes the smaller one, the two lying prostrate, with the legs
in boots under the body whose limbs wear only shoes.
If the rider happens fortunately to have the saddle between him and the
horse, his legs merely sustain a heavy weight, from which they are harmlessly
extricated the instant the animal rises.
Should he happen unfortunately to have the girths between him and the
horse, he lies, like Ariel in the cloven pine, "painfully imprisoned," in a
predicament of which it is impossible for any one to foretell the results.
As the quadruped is always more or less cowed by his fall, he remains usually
for about a minute or two as still as if he were dead.
All of a sudden, however, just as if a bayonet had been run into him, he
struggles to rise.
To do so it is necessary that all his feet should take hold of the ground. This
they are prevented from doing by the rider's boots, which, operating as a
handspike under the body, keep it in a horizontal position, thereby causing the
four legs, like two pairs of blacksmith's sledge-hammers, to continue to strike
heavily towards each other.
Between them lies, acting in this little tragedy the part of Anvil, the poor rider,
who can only avoid the hard blows of two fore iron shoes, by wincing from
them to within the reach of two hind ones.
This violent struggle eventually ends by the horse rising, leaving on the field
of battle, slightly, seriously, or desperately wounded, his master, whom he
never intended to hurt.
In the hunting field, the bent position in the saddle produces equally
unpleasant results. On man and horse coming cheerily to a fence, with what
mathematicians call "an unknown quantity" on the other side, if the rider sits
justly on his saddle, it is the horse and not he that receives the concussion of
any fall that may ensue, simply because the spring of his animal in taking the
leap had thrown his shoulders backwards, and consequently his head out of
danger; whereas the nose of the gentleman who had been riding alongside of
him in the bent attitude of a note of interrogation, is seen to plough into its
mother earth the instant the muzzle of his horse impinges upon it.
For exactly the same reasons, in every description of fall (and no volume
would be large enough to contain them all), similar results occur; and yet
there is no predicament in which "Toady" appears to greater disadvantage,
and so keenly feels it, than when, in following the hounds, he has to descend
a very precipitous and rather slippery grass hill.
If a horse be but properly dealt with, he can gallop down a turf hill with nearly
as much rapidity as along a race-course. A tea-table would stand ill at ease on
the declivity, because its limbs are immoveable; but a quadruped, by throwing
all his legs forwards and his body backwards, has the power to adjust himself,
with mathematical precision, to almost any descent.
To insure his safety, however, it is essential that he should be encouraged, by
a loose rein, to carry his head as low as possible, to enable him to take care of
his feet, and in case of treading on a rolling-stone to recover his balance by
throwing it up. Now, when in this position, if the rider, following the instinct
and the example of the horse, throws his weight backwards—in fact, if from
the saddle the backs of the two animals are separated from each other by
only a very small angle, both can descend the hill together at considerable
speed without the smallest danger. The only embarrassment the rider has to
contend against is an over-caution on the part of the horse, amounting to fear,
which induces him to try to take the slope diagonally, very likely to result in
the poor animal slipping up on his side. In keeping his head straight, however,
care must be taken not to induce him to raise it up; and when this little
difficulty is overcome, no other of any sort or kind remains to impede a safe
and rapid descent.
Seated on his saddle, in the attitude we have described, that admirable rider
Jack Shirley, whipper-in to the Tedworth hunt, with a large open clasp-knife in
his mouth, was one day observed fixing a piece of whipcord to his lash, while
following his hounds at a slapping pace, down hill, his reins lying nearly loose
on old "Gadsby's" neck.
On the other hand when a gentleman, however fearless he may be, sitting at
an angle of 45°, like a 13-inch mortar on its bed, attempts to ride down the
steep declivity described, the afflictions that befall him are really piteous, for
the instant his horse's fore legs sink considerably lower than the hind ones, he
feels that unless he holds on very tightly, he must inevitably pitch over the
bows of the vessel that is carrying him. To maintain his equilibrium he
therefore pulls a little at his curb-bit, which not only raises his horse's head till
it nearly touches his nose, but throws the animal and the weight he carries
into such a false position, that it becomes difficult and dangerous to advance.
The restrained quadruped, impatient to follow the horses before him, yet
altogether out of gear, on every little twitch at his bridle keeps chucking up his
head, until the rider, who a moment ago expected to fall over his ears, now
feels that he is going to glide backwards over his tail, which is nearly touching
the hill. In short, the poor horse is resting on his hocks instead of his hoofs,
with his fore feet barely touching the ground.
When a lot of riders find themselves in this hopeless attitude, they generally,
according to their amount of activity, crawl, jump, or vault from their saddles
to descend on foot, which they soon find very little improves their case, for
the heels of their boots not being, like horse-shoes, concave, take insufficient
hold of the turf; and thus while they are slipping, sliding, and tottering in the
descent, each linked to a quadruped that is bothering him to death, if, feeling
a little alarmed, they resolve to stop for a moment or two, their impatient
horses, unable to advance and unwilling to stand still, often compromise the
matter by running round their masters, with the chance of rolling them, like
ninepins, down the hill.
In galloping for many hours, and especially for many days, as soon as the
muscles of the rider, by getting tired, lose their obstinacy, it becomes
impossible for him, if he sits upright, to prevent his body undulating, to the
infinite relief of both parties, with every movement of the horse; whereas, if,
like an English jockey, whose seat is well adapted for galloping at the utmost
speed for a few minutes, he rides like a frog on a shovel, he inflicts upon his
whole frame, as well as upon the poor animal that carries him, an amount of
unnecessary fatigue which prematurely tires both.
For the foregoing reasons if gentlemen sportsmen who occupy on the road
and the hunting-field this false position, would but allow Mr. Calcraft, in his
peculiar way, to lift them about half a dozen times a few inches into the air,
and then, as a tallow-chandler dips his candles, lower them gently, easily, and
perpendicularly to their saddles, they would find themselves promoted in the
world to a seat on horseback which they would never wish to abandon.
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookgate.com

You might also like