Introduction
Ever wondered how MS Office 2000 repairs itself if any files are corrupted or missing? Just two lines of code can add this feature to your app.
First off, you must create an installer program from Windows Installer (free for Visual Studio 6.0 or VC++ 6.0 customers). The self-repairing services are provided via the Windows Installer system. If you are not developing for Windows 2000 only, make sure to set the project settings so that the Setup.exe file will install Windows Installer on the system if it is not already present (Windows Installer comes with Windows 2000, but is not included with previous versions of Windows).
Once your program is installed, it can verify and reinstall needed components with the following two lines.
MsiSetInternalUI(INSTALLUILEVEL_NONE,NULL);
MsiReinstallProduct("{A5A0D1C0-DF1A-11D3-99DC-00A0CCFFFAA1}",
REINSTALLMODE_FILEVERIFY | REINSTALLMODE_FILEMISSING
| REINSTALLMODE_FILEOLDERVERSION | REINSTALLMODE_REPAIR);
To compile, you will need to link your product with the installer library (msi.lib) and include the installer header msi.h.
Make sure to replace the product ID with the product ID that is in the settings dialog for your program. This is needed by Windows Installer. Additionally, the first line is not required. However, it will hide the GUI from the user (without it, a Windows installer dialog will appear). Other settings are:
NSTALLUILEVEL_FULL
INSTALLUILEVEL_REDUCED
INSTALLUILEVEL_BASIC
INSTALLUILEVEL_DEFAULT
INSTALLUILEVEL_NOCHANGE
INSTALLUILEVEL_NONE
For the reinstall function, possible options are:
REINSTALLMODE_REPAIR
REINSTALLMODE_FILEMISSING
REINSTALLMODE_FILEOLDERVERSION
REINSTALLMODE_FILEEQUALVERSION
REINSTALLMODE_FILEEXACT
REINSTALLMODE_FILEVERIFY
REINSTALLMODE_FILEREPLACE
REINSTALLMODE_USERDATA
REINSTALLMODE_MACHINEDATA
REINSTALLMODE_SHORTCUT
That's it!