VerFindFileVersion Example
InstallShield 2020 ยป InstallScript Language Reference
Note:To call this function in a Basic MSI setup, you must first create a custom action for the entry-point function, execute the custom action in a sequence or as the result of a dialog's control event, and then build the release.
/*--------------------------------------------------------------*\
*
* InstallShield Example Script
*
* Demonstrates the VerFindFileVersion and VerCompare functions.
*
* This script calls VerFindFileVersion to find the target file
* and retrieve its version information. If the specified
* target file is not found, the source file is copied to
* INSTALLDIR. If found, VerCompare is called to compare the
* version number of the EXAMPLE file found on the target
* system (the target file) to the version number of the file
* in SRCDIR (the source file). If the source file version
* number is newer than the target file, the target file is
* overwritten with the source file.
*
\*--------------------------------------------------------------*/
#define EXAMPLE "Stirinfc.dll"
#define SOURCE_VER "2.0.1.0"
#define TITLE "VerCompare and VerFindFileVersion"
// Include Ifx.h for built-in InstallScript function prototypes.
#include "Ifx.h"
export prototype ExFn_VerFindFileVersion(HWND);
function ExFn_VerFindFileVersion(hMSI)
STRING szFileName, svPath, svVersionNumber, szExistingVersion, szUpdateVersion;
STRING szTitle, szMsg;
NUMBER nResult, nCompareFlag;
begin
// Set the file to be updated.
szFileName = EXAMPLE;
// Find szFileName on the target system and retrieve its version number.
nResult = VerFindFileVersion(szFileName, svPath, svVersionNumber);
if (nResult = FILE_NOT_FOUND) then
// If szFileName not found, copy source file to INSTALLDIR.
szMsg = "Unable to locate %s. Copying %s to %s.";
SprintfBox (INFORMATION, TITLE, szMsg, szFileName, szFileName,
INSTALLDIR);
CopyFile (szFileName, szFileName);
abort;
elseif (nResult = FILE_NO_VERSION) then
// If no version number found, copy source file to svPath and exit.
szMsg = "%s version number not found. Copying %s to %s.";
SprintfBox (INFORMATION, TITLE, szMsg, szFileName, szFileName,
INSTALLDIR);
CopyFile (szFileName, szFileName);
abort;
elseif (nResult < 0) then
MessageBox ("VerFindFileVersion failed.", SEVERE);
abort;
endif;
// Compare the versions of the two files. It is assumed
// that the source version number is known.
szExistingVersion = svVersionNumber;
MessageBox (szExistingVersion, INFORMATION);
szUpdateVersion = SOURCE_VER;
MessageBox (szUpdateVersion, INFORMATION);
nCompareFlag = VERSION;
nResult = VerCompare (szUpdateVersion, szExistingVersion, nCompareFlag);
// If the source file is a more current version, install it.
if (nResult = GREATER_THAN) then
szMsg = "%s updated into the %s directory.";
SprintfBox (INFORMATION, TITLE, szMsg, szFileName, INSTALLDIR);
CopyFile (szFileName, szFileName);
// If the target file is a more current version, do not install.
elseif (nResult = LESS_THAN) then
szMsg = "No need for an upgrade, the most current version of %s is " +
"installed.";
SprintfBox (INFORMATION, TITLE, szMsg, szFileName);
// If both the target and source versions are the same, do not install.
elseif (nResult = EQUALS) then
MessageBox ("Versions are equal. No update needed.", INFORMATION);
endif;
end;