The Runtime Library Installer

Scripting

Adding the Installer

The first thing to do is to add the installer file to the Inno Setup script. By now you should be familiar with the scripting language, thus this step is very easy. I copied the installer into the "tmp" subdirectory:

Once again notice that the "exe" is installed in the users temporary folder.

Check

The "Check" parameter is the name of a function that is to be called and evaluated before the "exe" is run. We will see the code of that function in a moment, for now it just matters to know that the "vc_redist.x64.exe" will only be run if the "check"-function returns true.

StatusMsg

The "StatusMsg" parameter contains the text that "Inno Setup" will display as the Visual Studio runtimes are being installed.

Pascal

Welcome back to the good old times! An Inno Setup-script can contain Pascal code. We will write a simple script to check whether the Visual C++ 2017 Redistributables are already installed or not.

Unique IDs

As we learned way back in a previous tutorial, each Windows program has a unique ID, thus to check whether the Visual C++ 2017 Redistributables are installed or not, we simply query whether software with a given ID is registered in the registry or not. The ID for the latest Visual C++ 2017 Redistributables are as follows:

You can find product codes for other Visual Studio versions in the registry under "HKEY_CLASSES_ROOT\Installer\Dependencies"; for example "HKEY_CLASSES_ROOT\Installer\Dependencies\Microsoft.VS.VC_RuntimeMinimumVSU_x86,v14".

Installation State

To query the installation state of a certain program, Microsoft offers the MsiQueryProductState function:

INSTALLSTATE MsiQueryProductStateA(
LPCSTR szProduct
);

The parameter for the function, a long pointer to a constant string, specifies the product code that identifies the product to be queried.

The return value is one of the following:

Value

Meaning

INSTALLSTATE_ABSENT

The product is installed for a different user.

INSTALLSTATE_ADVERTISED

The product is advertised but not installed.

INSTALLSTATE_DEFAULT

The product is installed for the current user.

INSTALLSTATE_INVALIDARG

An invalid parameter was passed to the function.

INSTALLSTATE_UNKNOWN

The product is neither advertised or installed.

To use this function inside our "Inno Setup"-script, we first define the return values as constant variables:

Remember, when we added the installation file for the Visual C++ Redistributables, we added a "Check" parameter: VCRedistNeedsInstall. Now before the installation starts, the function "VCRedistNeedsInstall" is called, which in turn calls the "VCVersionInstalled" function, which uses the function defined by Windows to check whether the software we are querying for is installed or not.

If, and only if, the function VCRedistNeedsInstall returns true, that is, if the prerequisite software is not installed, Inno Setup runs the installer for the requested software.