RegDBCreateKeyEx Example

InstallShield 2020 ยป 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 RegDBCreateKeyEx and RegDBKeyExist functions.

*

* First, RegDBCreateKeyEx is called to create a subkey with no

* class value in the HKEY_CLASSES_ROOT key.  Then, RegDBKeyExist

* is then called to check if the key was created.

*

* RegDBCreateKeyEx is called again to create a multi-level subkey

* with a class value associated with it under HKEY_CLASSES_ROOT.

* Then RegDBKeyExist is called again to check for the existence

* of the new key.

*

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

 

#define TITLE_TEXT "RegDBCreateKeyEx & RegDBKeyExist"

 

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

#include "Ifx.h"

 

export prototype ExFn_RegDBCreateKeyEx(HWND);

 

function ExFn_RegDBCreateKeyEx(hMSI)

    STRING szKey, szClass, szKeyRoot, szMsg, svLogFile;

    NUMBER nResult1, nResult2;

begin

 

    // Create a key with no class value.

    szKey   = "CreateKeyExample";

    szClass = "";

 

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

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

        abort;

    else

        SprintfBox (INFORMATION, TITLE_TEXT, "Successfully created: %s", szKey);

 

        // Check to see if the key just created exists.

        if (RegDBKeyExist (szKey) < 0) then

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

        else

            SprintfBox (INFORMATION, TITLE_TEXT, "%s exists.", szKey);

        endif;

    endif;

 

    if (RegDBDeleteKey (szKey) < 0) then

        MessageBox ("RegDBDeleteKey failed.", SEVERE);

    endif;

 

    // Create a key with more than one sublevel and a class value.

    szKey     = "ShareWare\\Games\\CoolChess";

    szClass   = "LastPlayed";

    szKeyRoot = "ShareWare";

 

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

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

        abort;

    else

        SprintfBox (INFORMATION, TITLE_TEXT, "Successfully created: %s", szKey);

 

        // Check if the newly created multi-level key exists.

        if (RegDBKeyExist (szKeyRoot) < 0) then

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

        else

            SprintfBox (INFORMATION, TITLE_TEXT, "%s exists.", szKey);

        endif;

    endif;

 

    if (RegDBDeleteKey (szKey) < 0) then

        MessageBox ("RegDBDeleteKey failed.", SEVERE);

    endif;

 

end;