Http://blogs.msdn.com/ B /astebner/archive/2007/01/16/mailbag-how-to-detect-the-presence-of-the-vc-8-0-runtime-redistributable-package.aspx
Question:
I am building an installer that will include the Visual C ++ (VC) 8.0 runtime files redistributable package (vcredist_x86.exe, vcredist_x64.exe and/or vcredist_ia64.exe) as a prerequisite. how can I detect whether or not this package is already installed on the user's system so that my installer can skip installing it when appropriate?
Answer:
There was not a specific detection mechanic designed and built into VC 8.0 runtime files redistributable setup packages. the setup bootstrapper that ships with Visual Studio 2005 uses the following algorithm to check for the existence of these packages:
- Call the msiqueryproductstate API
- Pass in the product code for the package that you want to detect based on the list below
- Check the return value of this API. If it is anything other than installstate_default, the package is not yet installed
Visual c ++ 2005 runtime files
- Visual c ++ 2005 redistributable package (x86)-{A49F249F-0C91-497F-86DF-B2585E8E76B7}
- Visual c ++ 2005 redistributable package (x64)-{6e8e85e8-ce4b-4ff5-91f7-04999c9fae6a}
- Visual c ++ 2005 redistributable package (IA64)-{03ed71ea-f531-4407-aabd-1c31bce8e187}
Visual c ++ 2005 SP1 runtime files
- Visual c ++ 2005 SP1 redistributable package (x86)-{7299052b-02a4-4627-81f2-18da5d550d}
- Visual c ++ 2005 SP1 redistributable package (x64)-{071c9b48-7c32-4621-a0ac-3f809523288f}
- Visual c ++ 2005 SP1 redistributable package (IA64)-{0f8fb34e-675e-42ed-850b-29d98c2ece08}
Visual c ++ 2005 SP1 ATL Security Update runtime files
- Visual c ++ 2005 SP1 ATL Security Update redistributable package (x86)-{837b34e3-7c30-493c-8f6a-2b0f04e2912c}
- Visual c ++ 2005 SP1 ATL Security Update redistributable package (x64)-{6ce5bae9-d3ca-4b99-891a-1dc6c118a5fc}
- Visual c ++ 2005 SP1 ATL Security Update redistributable package (IA64)-{85025851-a784-46d8-950d-05cb3ca43a13}
However, this algorithm is somewhat incomplete. it does not cover cases where a user has installed some other application on the system that provided des the VC 8.0 runtime redistributable merge modules (msms) as part of its MSI package. it also does not cover the case of Windows Vista, where the VC 8.0 runtime files are installed as part of the OS.
The safest way for a setup to manage detection for the VC 8.0 runtime redistributable package is to use an algorithm similar to the one listed above to check for the MSI product code and then install if it is not yet installed. this may lead to a few cases where the setup will install it when it doesn' t technically need, but that is better than any scenarios where it cocould might end up not installing it when the VC runtime files are not yet present. in addition, using this approach will add a reference count to the VC runtime files to prevent scenarios where uninstalling some other application that includes des the VC runtime msms causes the VC runtime files to be removed from the system.
One important note-the VC runtime redistributable packages require that the system has at least Windows Installer 3.0 (and ideally Windows Installer 3.1 because any future hotfixes produced for this package will require Windows Installer 3.1 ). if your setup is going to install the VC runtime redist package, it shoshould also check for the presence of Windows Installer 3.x and install it as well if it is not yet installed on the system.
Other options for installing the VC 8.0 runtime files
I also want to point out that there are other options for applications that depend on the VC 8.0 runtime files Besides redistributing the vcredist_x86 or vcredist_x64 MSI packages.
- Include the VC runtime msms in your MSI package directly-This can cause issues like the ones I described in this previous blog post, but in some cases this is the easiest solution
- Statically link to the VC runtimes when building your application-This increases the size of your binaries but eliminates the need to validate that these runtime files are present on users 'systems at setup time for your application
- Install the VC runtimes to a local folder for use only with your application-This complicates the installation logic in your MSI and causes Hotfixes to not apply for your the version of these runtime files encoded with your application on Windows 2000
These options have varous pros and cons, and the choice you make depends on your applications and the scenarios you want to support. there is additional discussions of some of the trade-offs on the msdn forums (for example, this post and this post ). I encourage you to read some of these posts and others that are stored as links within them before making your setup packaging demo-for the VC 8.0 runtime files.
<Update date = "1/24/2006"> added information about the IA64 version of the VC redist package. </update>
<Update date = "11/19/2009"> added information about VC ++ 2005 SP1 and VC ++ 2005 SP1 ATL Security Update packages. </update>