VerSearchAndUpdateFile

InstallShield 2019 » InstallScript Language Reference

The VerSearchAndUpdateFile function searches for the specified file and installs a newer version of the file if necessary. If the function finds the file, it compares the version number of the existing file to the version number of the new file. If the existing file is older, it is replaced with the new file. The new file must be in the directory specified by the system variable SRCDIR. If the function does not find an existing file, it copies the new file to the target system. Windows decides where the file is installed depending on the type of the file. For example, DLLs and system drivers are installed in the Windows system folder. For information about the Windows system folder, see the documentation for the InstallScript system variable WINSYSDIR.

VerFindFileVersion uses the following search algorithm to find the file (searches the folders in the following order):

1. Windows folder
2. Windows system folder
3. The folder specified by the TARGETDIR system variable (in InstallScript installations) or the INSTALLDIR system variable (in Basic MSI or InstallScript MSI installations)
4. The folders specified by the PATH environment variable
5. The folder from which Setup.exe is running

Note • For file transfer, an alternative to VerSearchAndUpdateFile is XCopyFile—which can do check version, mark locked .dll and .exe files for update after system reboot, and increment registry reference counters for shared .dll and .exe files.

Syntax

VerSearchAndUpdateFile ( szFileName, nUpdateFlag, svInstalledFile );

Parameters

VerSearchAndUpdateFile Parameters

Parameter

Description

szFileName

Specifies the unqualified name of the file to install. Do not specify a drive designation or path in this parameter.

nUpdateFlag

Specifies whether the file should be updated unconditionally or only if the version of the file found on the target system is older than the version of the file that you have shipped. Pass one of the following predefined constants in this parameter:

VER_UPDATE_COND—Updates the existing file only if it is an older version.
VER_UPDATE_ALWAYS—Updates the existing file even if it is a newer version.

svInstalledFile

Returns the fully qualified name of the file installed by the function. If the file you want to replace is in use, the file is installed to the same directory with a slightly different name. The file is renamed with a tilde (~) character in the first character of the extension. For example, if you are installing the file Shell.dll and the file is locked, the file is copied as Shell.~ll. The name is returned in this variable.

Return Values

VerSearchAndUpdateFile Return Values

Return Value

Description

FILE_INSTALLED (0)

Function was successful in installing the file.

FILE_IS_LOCKED (-4)

Indicates that the file is in use by Windows and cannot be replaced. The new file is copied to the same directory with a new name.

FILE_NO_VERSION (-8)

Indicates that the file was found, but it did not contain version information. File update is not performed.

FILE_RD_ONLY (-5)

Indicates that the existing file is write protected. The script should reset the read-only flag of the destination file before proceeding with the setup and then attempt to install the file again.

FILE_SRC_OLD (-7)

Indicates that the file to install has the same date or is older than the preexisting file.

OUT_OF_DISK_SPACE (-6)

Indicates that the function cannot create the file due to insufficient disk space on the destination drive. File update is not performed.

VER_DLL_NOT_FOUND (-3)

Indicates Ver.dll was not found. File update is not performed.

OTHER_FAILURE (-1)

Indicates an unspecified error occurred. File update is not performed.

See Also