RegDBSetDefaultRoot Example

InstallShield 2012 Spring » 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 RegDBSetDefaultRoot function.

*

* RegDBSetDefaultRoot is called to set the default root key for

* the RegDBCreateKeyEx function.

*

* Note:  Windows does not allow the creation of a key

*        directly under HKEY_LOCAL_MACHINE or HKEY_USERS.

*

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

 

#define TITLE "RegDBSetDefaultRoot Example"

 

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

#include "Ifx.h"

 

export prototype ExFn_RegDBSetDefaultRoot(HWND);

 

function ExFn_RegDBSetDefaultRoot(hMSI)

    STRING szKey, szClass, szMsg, szTitle;

    NUMBER nRootKey;

begin

 

    // Create a subkey in the HKEY_CLASSES_ROOT key (default).

    szKey   = "Test Key";

    szClass = "";

 

    if (RegDBCreateKeyEx (szKey, szClass) < 0) then

        MessageBox ("RegDBCreateKeyEx failed.", SEVERE);

        abort;

    else

        szMsg = "Successfully created %s in HKEY_CLASSES_ROOT.";

        SprintfBox (INFORMATION, TITLE, szMsg, szKey);

    endif;

 

    // Set the root key to HKEY_LOCAL_MACHINE.

    nRootKey = HKEY_LOCAL_MACHINE;

 

    if (RegDBSetDefaultRoot (nRootKey) < 0) then

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

    else

        MessageBox ("Root key successfully set to HKEY_LOCAL_MACHINE.",

                   INFORMATION);

    endif;

 

    // Create a subkey in the HKEY_LOCAL_MACHINE key.

    if (RegDBCreateKeyEx (szKey, szClass) < 0) then

        MessageBox ("RegDBCreateKeyEx failed.", SEVERE);

        abort;

    else

        szMsg = "Successfully created %s in HKEY_LOCAL_MACHINE";

        SprintfBox (INFORMATION, TITLE, szMsg, szKey);

    endif;

 

    // Delete the example subkey in HKEY_LOCAL_MACHINE.

    if (RegDBDeleteKey (szKey) < 0) then

        MessageBox ("RegDBDeleteKey failed.", SEVERE);

    else

        szMsg = "Successfully deleted %s in HKEY_LOCAL_MACHINE";

        SprintfBox (INFORMATION, TITLE, szMsg, szKey);

    endif;

 

    // Set the root key to HKEY_CLASSES_ROOT again.

    nRootKey = HKEY_CLASSES_ROOT;

 

    if (RegDBSetDefaultRoot (nRootKey) < 0) then

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

    else

        MessageBox ("Root key successfully set to HKEY_CLASSES_ROOT.",

                   INFORMATION);

    endif;

 

    if (RegDBDeleteKey (szKey) < 0) then

        MessageBox ("RegDBDeleteKey failed.", SEVERE);

    else

        szMsg = "Successfully deleted %s in HKEY_CLASSES_ROOT";

        SprintfBox (INFORMATION, TITLE, szMsg, szKey);

    endif;

 

end;