Windows Installer API Functions Example
InstallShield 2020 ยป InstallScript Language Reference
/*-----------------------------------------------------------*\
*
* InstallShield Example Script
*
* Demonstrates several Windows API functions that are used
* to access the tables of the .msi database at run time and
* add temporary records.
*
* Note: Before running this script, add a ListBox control to
* the ReadyToInstall dialog, and associate the control
* with the property LISTBOXPROP.
*
* This script populates the ListBox control in the ReadyToInstall
* dialog with the current values of every property listed in
* the Property table. The end user's selection for the ListBox
* is stored in LISTBOXPROP.
*
\*--------------------------------------------------------------*/
// Include Ifx.h for built-in InstallScript function prototypes.
#include "ifx.h"
// InstallScript custom action entry point
export prototype PropDisplay(HWND);
function PropDisplay(hInstall)
HWND hDB, hViewlist, hRecordlist;
HWND hViewprop, hRecordprop;
NUMBER nBuffer, r;
STRING svPropname, svPropvalue;
begin
hDB = MsiGetActiveDatabase(hInstall);
// open view into ListBox table
MsiDatabaseOpenView(hDB,
"SELECT * FROM `ListBox` WHERE `Property`='LISTBOXPROP'",
hViewlist);
MsiViewExecute(hViewlist, NULL);
// open view into Property table
MsiDatabaseOpenView(hDB,
"SELECT * FROM `Property`", hViewprop);
MsiViewExecute(hViewprop, NULL);
r = 0;
// for each Property record, add PROPNAME="value" record
// to ListBox table
while (MsiViewFetch(hViewprop, hRecordprop) != ERROR_NO_MORE_ITEMS)
nBuffer = 256; // set size buffer
MsiRecordGetString(hRecordprop, 1, svPropname, nBuffer);
nBuffer = 256; // reset size buffer
MsiGetProperty(hInstall, svPropname, svPropvalue, nBuffer);
r = r + 1;
hRecordlist = MsiCreateRecord(4);
MsiRecordSetString(hRecordlist, 1, "LISTBOXPROP");
MsiRecordSetInteger(hRecordlist, 2, r);
MsiRecordSetString(hRecordlist, 3, svPropname);
MsiRecordSetString(hRecordlist, 4, svPropname + "=" + svPropvalue);
// can only temporarily modify running .msi database
MsiViewModify(hViewlist, MSIMODIFY_INSERT_TEMPORARY, hRecordlist);
endwhile;
MsiViewClose(hViewlist);
MsiViewClose(hViewprop);
end;