VerUpdateFile Example

InstallShield 2016 » 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 VerUpdateFile function.

*

* This script calls VerUpdateFile twice to update a Windows

* accessory.

*

\*--------------------------------------------------------------*/

 

#define APPFILE "Notepad.exe"

#define TITLE   "VerUpdateFile Example"

 

// Include Ifx.h for built-in InstallScript function prototypes.

#include "Ifx.h"

 

export prototype ExFn_VerUpdateFile(HWND);

 

function ExFn_VerUpdateFile(hMSI)

    STRING svInstalledFilePath, szTitle, szMsg;

    NUMBER nResult;

    BOOL   bDone;

begin

    

    //  Update the file regardless of file version.

    nResult = VerUpdateFile (APPFILE, VER_UPDATE_ALWAYS, svInstalledFilePath);

    

    if (nResult < 0) then

        MessageBox ("First call to VerUpdateFile failed.", SEVERE);

    else

        szMsg = "%s successfully updated.";

        SprintfBox (INFORMATION, TITLE, szMsg, APPFILE);

    endif;

 

    // Update the files only if the target files are more recent.

    nResult = VerUpdateFile (APPFILE, VER_UPDATE_COND, svInstalledFilePath);

 

    if (nResult < 0) then

        MessageBox ("Second call to VerUpdateFile failed.", SEVERE);

    endif;

 

end;