RegDBSetItem Example

InstallShield 2014 ยป 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 RegDBSetItem and RegDBGetItem functions.

*

* This script sets several registry keys;  then it gets those

* keys and displays their current values.

*

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

 

#define  COMPANY_NAME       "ExampleCompany"

#define  PRODUCT_NAME       "ExampleProduct"

#define  VERSION_NUMBER     "5.00.00"

#define  PRODUCT_KEY        "EXAMPLE.EXE"

#define  DEINST_KEY         "ExampleDeinstKey"

#define  APP_DEF_LOG_PATH   "C:\\EXAMPLE\\TEMP"

#define  APP_PATH           "C:\\EXAMPLE"

#define  APP_DEF_PATH       "C:\\EXAMPLE\\TARGET"

#define  UNINSTALL_NAME     "ExampleUninstallName"

#define TITLE               "RegDBSetItem Example"

 

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

#include "Ifx.h"

 

export prototype ExFn_RegDBSetItem(HWND);

 

function ExFn_RegDBSetItem(hMSI)

    STRING svLogFile;

    STRING svValue, szTitle;

begin

 

    // Set the root key.

    RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE);

 

    // Set installation and uninstallation information in

    // order to call RegDBSetItem and RegDBGetItem.

    InstallationInfo (COMPANY_NAME, PRODUCT_NAME, VERSION_NUMBER, PRODUCT_KEY);

    DeinstallStart (APP_DEF_LOG_PATH, svLogFile, DEINST_KEY, 0);

 

    // Set the value of the application path key in the

    // registry to the value of szAppPath.

    if (RegDBSetItem (REGDB_APPPATH, APP_PATH) < 0) then

        MessageBox ("Unable to set application path key.", SEVERE);

    else

        SprintfBox (INFORMATION, TITLE, "RegDBSetItem set the application " +

                   "path key to %s.", APP_PATH);

    endif;

 

    // Set the value of the application default path key in

    // the registry to the value of szAppDefPath.

    if (RegDBSetItem(REGDB_APPPATH_DEFAULT, APP_DEF_PATH) < 0) then

        MessageBox ("Unable to set application default path key.", SEVERE);

    else

        SprintfBox (INFORMATION, TITLE, "RegDBSetItem set the application " +

                   "default path key to %s.", APP_DEF_PATH);

    endif;

 

    // Set the value of the uninstall name key in the

    // registry to the value of szUninstallName.

    if (RegDBSetItem (REGDB_UNINSTALL_NAME, UNINSTALL_NAME) < 0) then

        MessageBox ("Unable to set uninstall name key.", SEVERE);

    else

        SprintfBox (INFORMATION, TITLE, "RegDBSetItem set the uninstall " +

                   "name key to %s.", UNINSTALL_NAME);

    endif;

 

    // Set up title parameter for call to SprintfBox.

    szTitle = "RegDBGetItem";

 

    // Get the value of the application path key from the registry.

    if (RegDBGetItem (REGDB_APPPATH, svValue) < 0) then

        MessageBox ("Unable to get value of application path key.", SEVERE);

    else

        SprintfBox (INFORMATION, TITLE, "RegDBGetItem retrieved the value " +

                   "of the application path key: %s.", svValue);

    endif;

 

    // Get the value of the application default path key in

    // the registry.

    if (RegDBGetItem (REGDB_APPPATH_DEFAULT, svValue) < 0) then

        MessageBox ("Unable to get application default path key", SEVERE);

    else

        SprintfBox (INFORMATION, TITLE, "RegDBGetItem retrieved the value " +

                   "of the application default path key: %s.", svValue);

    endif;

 

    // Get the value of the uninstall name key from the registry.

    if (RegDBGetItem (REGDB_UNINSTALL_NAME, svValue) < 0) then

        MessageBox ("Unable to get application uninstall name key.", SEVERE);

    else

        SprintfBox (INFORMATION, TITLE, "RegDBGetItem retrieved the value " +

                   "of the uninstallation name key: %s.", svValue);

    endif;

 

end;