![]()
|
InstallShield 12 » 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 functions InstallationInfo, DeinstallStart,
* and DeinstallSetReference.
*
* InstallationInfo is called to create an application
* information key in the registry.
*
* DeinstallStart is called to create an uninstallation key in
* the registry. RegDBSetItem is called to set the [DisplayName]
* value in the uninstallation key. This value is displayed in
* the Windows95 and WinNT 4.0 'Add/Remove Programs Properties'
* dialog.
*
* DeinstallSetReference is called to specify a file that, if
* locked at uninstallation time, prevents uninstallation from
* continuing.
*
* To run properly, this example requires at least a single
* component that installs a file group containing Notepad.exe.
* If you use an .exe file other than Notepad.exe, be sure to
* change the PRODUCT_KEY define accordingly.
*
* To see the results of DeinstallSetReference, open the Notepad
* installed by this example and then try to uninstall it while
* it's open.
*
\*--------------------------------------------------------------*/
#define COMPANY_NAME "ExampleCompany"
#define PRODUCT_NAME "ExampleApp2"
#define PRODUCT_VERSION "2.0"
#define PRODUCT_KEY "Notepad.exe"
#define DEINST_KEY "ExApp2Uninstall"
prototype HandleComponentError (NUMBER);
// Include Ifx.h for built-in InstallScript function prototypes.
#include "Ifx.h"
export prototype ExFn_DeinstallStart(HWND);
function ExFn_DeinstallStart(hMSI)
STRING szCompany, szProduct, szVersion, szProductKey;
STRING svDir, svLogFile, szKey, svPath;
NUMBER nvDisk, nResult;
begin
// Disable the Back button in setup dialogs.
Disable(BACKBUTTON);
// Initialize variables.
szCompany = COMPANY_NAME;
szProduct = PRODUCT_NAME;
szVersion = PRODUCT_VERSION;
szProductKey = PRODUCT_KEY;
SdProductName ( szProduct );
// Create the application information key and provide
// information to create the per application paths key.
InstallationInfo(szCompany, szProduct, szVersion, szProductKey);
// The Welcome dialog uses the product name value
// set by SdProductName.
Welcome ("", 0);
INSTALLDIR = PROGRAMFILES ^ COMPANY_NAME;
AskDestPath ("Destination Location",
"Select a destination location.",
INSTALLDIR , 0 );
szKey = DEINST_KEY;
/*--------------------------------------------------------------*\
*
* DeinstallStart initializes the uninstall log file using the
* values provided by InstallationInfo. DeinstallStart also
* creates the applicationuninstallation key using the values
* given to it.
*
* Note: Call DeinstallStart immediately after InstallationInfo
* so that there are no intervening dialogs or events that
* so that there abort. If an exit or abort occurs before
* DeinstallStart is called, certain registry entries may
* not be removed because the uninstalllog file has not
* yet been initialized.
*
\*--------------------------------------------------------------*/
DeinstallStart (INSTALLDIR, svLogFile, szKey, 0);
RegDBSetItem (REGDB_UNINSTALL_NAME, PRODUCT_NAME);
// Specify a file that, if locked at uninstallation time,
// will prevent uninstallation from continuing.
DeinstallSetReference (INSTALLDIR ^ PRODUCT_KEY);
// Transfer files and handle any errors.
SdShowMsg ("Installing program files...", TRUE);
nResult = ComponentMoveData ( MEDIA , nvDisk , 0 );
HandleComponentError (nResult);
Delay(1);
SdShowMsg ("Installing program files...", FALSE);
// Add .exe icon to Start Programs menu.
SdShowMsg ("Adding icon to Start Programs menu...", TRUE);
svPath = INSTALLDIR ^ PRODUCT_KEY;
LongPathToQuote (svPath, TRUE );
AddFolderIcon (FOLDER_PROGRAMS, PRODUCT_NAME, svPath,
"", "", 0, "", REPLACE);
Delay(1);
SdShowMsg ("Adding icon to Start Programs menu...", FALSE);
end;
/*--------------------------------------------------------------*\
*
* Function: HandleComponentError
*
* Purpose: This function evaluates the value returned by a
* Component function and, if the value is less than
* zero, displays the error number and aborts the
* setup.
*
\*--------------------------------------------------------------*/
function HandleComponentError( nResult )
NUMBER nvError;
STRING svMedia, svComponent, svFileGroup, svFile;
begin
if (nResult < 0) then
ComponentError (svMedia, svComponent, svFileGroup, svFile,
nvError);
SprintfBox (INFORMATION, "Data Transfer Error Information",
"ComponentError returned the" +
"following data transfer error.\n" +
"Setup will now abort.\n\n" +
"Media Name: %s\nComponent: %s\nFile Group: %s\n" +
"File: %s\nError Number: %ld",
svMedia, svComponent, svFileGroup, svFile, nvError);
abort;
endif;
end;
|
|
copyright contact |