Creating Dynamic And
Robust Applications With
®
The Windows Installer
Mike Kelly
Lead Software Design Engineer
Microsoft Office TCO Team
Microsoft Corporation
Agenda
Office 2000 demand install demo
Quick refresher on architecture
Installer API overview
Install sample application - MsiSpy tool
Examine sample application code
in debugger
Questions
Demo
Office 2000 demand install
Architecture
Active
Directory
Package format
Describes required state
API Installer Package Shell, COM,
and files and App MGMT
Install and configure
Applications Client
packages and features
Query machine state
Build packages
Windows installer API
Service built into OS
Service on Windows NT Windows installer
service
Performs all
install operations
Configuration data
Tracks state of Config
File System Registry
installed apps Data
Features, Components,
Resources, And Entry Points
Product
(Office)
Feature 1 Feature 2
(Word) (Excel)
Feature 3 Feature 4
(Word Speller) (Excel Speller)
Component 1 Component 2 Component 3
(WordCore) (MS Speller) (ExcelCore)
Resource Entry Point Resource Entry Point Resource Entry Point
(winword.exe) (Shortcut) (Mssp.dll) (CLSID) (excel.exe) (Shortcut)
Resource Entry Point Resource Resource Entry Point
(Registry Key) (.doc) (Registry Key) (Registry Key) (.xls)
An Installer-Aware App
Feature/component definitions in code
Get product ID at app initialization
Enable UI based on feature state
MsiQueryFeatureState
Install features as they are used
MsiUseFeature (“golden pyramid”)
Error-trapping approach
Use installer to find paths
MsiProvideComponent
MsiProvideQualifiedComponent
Installer Datatypes
Product ID
Product code - a string GUID
Can hardcode this or hardcode “core
component ID” (e.g. For your EXE)
Depends on whether you ship multiple
products with your application or not
Many installer APIs need product code
TCHAR szCoreComponent[] =
TEXT("{5CB2D5F5-19DD-11d1-9A9D-006097C4E489}");
if (MsiGetProductCode( szCoreComponent,
vszProductCode) != ERROR_SUCCESS)
return FALSE;
Installer Datatypes
Feature/Component IDs
Feature IDs are text strings
Limited to MAX_FEATURE_CHARS
Internal names
Evaluated relative to product code
Component IDs are GUID strings
Global across all products
Components have a key file -- use
MsiGetComponentPath or MsiProvideComponent
to get path to the component key file
Component IDs change when components
change in incompatible ways
Installer Datatypes
INSTALLSTATE
Gives “installed state” of a feature, product
or component
MsiQueryFeatureState to obtain for a feature
Example: speller
Remember that components are only installed as
part of a feature, so feature INSTALLSTATE is
what is interesting
INSTALLSTATE_LOCAL
INSTALLSTATE_SOURCE
INSTALLSTATE_ABSENT
Feature is not available to be installed
Installer Datatypes
INSTALLSTATE
INSTALLSTATE_ADVERTISED
Feature is not installed, but can be installed
Use MsiConfigureFeatureState to install
INSTALLSTATE_DEFAULT installs the feature
“normally” (either local or source)
INSTALLSTATE_BROKEN
Feature is installed, but not intact
INSTALLSTATE_SOURCEABSENT
Feature is installed to run from source but the
source is missing (e.g., CD missing, net down)
Installer Datatypes
INSTALLMODE
How much work installer should do to
provide a feature or component
MsiUseFeatureEx
MsiProvideComponent
MsiProvideQualifiedComponent
INSTALLMODE_DEFAULT
INSTALLMODE_EXISTING
INSTALLMODE_NODETECTION
Save one GetFileAttributesEx call
Installer Datatypes
REINSTALLMODE
Used when repairing a feature
Can use in place of INSTALLMODE flags
MsiReinstallFeature
MsiReinstallProduct
REINSTALLMODE_FILEMISSING
REINSTALLMODE_FILEEXACT
REINSTALLMODE_FILEVERIFY
REINSTALLMODE_MACHINEDATA
REINSTALLMODE_USERDATA
Using Features
MsiUseFeature when a feature is used
Increments feature’s usage count (obtain
with MsiGetFeatureUsage)
If feature not installed, install it!
Use MsiConfigureFeature to install
MsiUseFeatureEx combines these.
If needed, get path to a component key
file using MsiGetComponentPath
For use with LoadLibrary, CreateFile, etc.
Resiliency
What if LoadLibrary fails?
Features can be broken
User deletes file (LoadLibrary fails)
User removes necessary registry info
(CoCreateInstance fails)
Just offer to reinstall the feature!
UINT MsiReinstallFeature(
LPCTSTR szProduct, // product code
LPCTSTR szFeature, // feature ID
LPCTSTR dwReinstallMode);
Performance Tip
Installer will verify feature install states
Registry lookups + one GetFileAttributes
call per feature component
For very commonly used features (e.g.,
application boot), you can first just look
in the “usual place” (e.g., app directory)
If LoadLibrary fails, fall back on installer
API to find and/or reinstall feature
Lose feature usage metrics, some safety
Published Components
Also called “Qualified Components”
MsiProvideQualifiedComponent
MsiEnumComponentQualifiers
Very flexible scheme for managing lists
of components
Examples: text converters, wizards,
templates, any per-language component
Flexible way of sharing features across
products without hard coding
component IDs
Published Components
UINT MsiProvideQualifiedComponent(
LPCTSTR szCategory, // category GUID
LPCTSTR szQualifier, // qualifier string
DWORD dwInstallMode, // the install mode
LPTSTR lpPathBuf, // in/out path,
// NULL if unneeded
DWORD *pcchPathBuf); // in/out
Category GUID not a component ID!
Think of as “array name”
Array index is szQualifier
File Type, LCID, etc.
Published Components
{5CB2D5F5-19DD-11d1-9A9D-006097C4E489}
“1033”, “English”
{5CB2D5F5-19DD-11d1-9A9D-006097C4E500}
APPENU.DLL
“1036”, “French”
{5CB2D5F5-19DD-11d1-9A9D-006097C4E501}
APPFRA.DLL
“1031”, “German”
{5CB2D5F5-19DD-11d1-9A9D-006097C4E502}
APPDEU.DLL
Published Components
UINT MsiEnumComponentQualifiers(
LPCTSTR szCategory, // category GUID
DWORD iIndex, // 0-based index
LPTSTR szQualifier, // qualifier string
DWORD *pcchQualifier // in/out
LPTSTR szAppData, // AppData string
DWORD *pcchAppData); // in/out
Use to populate listbox
Office 2000: list of languages supported
AppData is intended for UI
Office 2000: user-readable language name
Shell Support
“Installer Token”: New form of Shell
shortcut on Internet Explorer 4.01 SP 1
Shell, Windows 98 and Windows NT® 5.0
Encapsulates Product/Feature/Component
Can live in Start menu or on Desktop
Shell will detect that shortcut is an
Installer Descriptor and invoke installer
to provide the component path
Free install on demand for apps
Note: only installs product’s main feature
COM Support
“Installer Descriptor” can be used in
COM registry on Windows NT 5.0
Same format as Shell shortcut
OLE will invoke installer to provide the
component path
Free install on demand for
COM components
Note: only installs target feature
Demo
MsiSpy sample
Next Steps
Add resiliency to your application
Use Published Components to share
features across applications
Use Windows installer to
Make “run from network server” free
Make automated deployment easy
Allow users/administrators to tailor
application install size without losing
any functionality
Use the installer for your application!
Call To Action
Empower your applications for management!
Separate user and machine data
See MGMT 001
Policy Enable Your Application
See MGMT 001, MGMT 006
Create a Windows installer package
See MGMT 003, MGMT 004
Leverage the Windows installer API
See MGMT 005
Leverage Active Directory for Application Data
See DS 05, DS 06
Windows NT 5.0 Logo
Leverage your investment in
Windows installer
Install/uninstall is top concern among customers
1 of 4 key areas of the new Windows NT 5.0 logo
Follow up info
Draft requirements:
On the conference DVD
www.microsoft.com/windows/winlogo/developer
Feedback: logotalk@microsoft.com by 11/15
Questions And Answers
Product Codes
Product Product Code
Foo 1.0 A
Foo Pro 1.0 B
Foo Pro 1.1 B
Foo Pro 2.0 C