Mailbag: How to detect the presence of the VC 8.0 runtime redistributable package

Question:

I am building an installer that will include the Visual C++ (VC) 8.0 runtime files redistributable package (vcredist_x86.exevcredist_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 mechanism 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:

  1. Call the MsiQueryProductState API
  2. Pass in the product code for the package that you want to detect based on the list below  
  3. 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 SP1 runtime files

Visual C++ 2005 SP1 ATL Security Update runtime files

However, this algorithm is somewhat incomplete.  It does not cover cases where a user has installed some other application on the system that includes 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.  (Note - versions of Windows newer than Windows Vista do not treat the VC++ runtime files as system files anymore.  See this knowledge base article for more information.)

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 to, but that is better than any scenarios where it could 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 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 should 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 included with your application on Windows 2000

These options have various 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 included as links within them before making your setup packaging decision 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>

<update date="2/11/2015"> Added a link to a knowledge base article to help clarify that post-Vista versions of Windows do not include VC++ runtime files as OS components. </update>