RegDBConnectRegistry Example

InstallShield 2015 ยป 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 RegDBConnectRegistry function and

* RegDBDisConnectRegistry function.

*

* Note: In order for this script to run properly, you must set

*       the preprocessor constants to a valid remote computer

*       with remote administration enabled.  Both computers

*       must also have the remote-registry service enabled.

*

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

 

#define REMOTE "IShield_NT1"

 

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

#include "Ifx.h"

 

export prototype ExFn_RegDBConnectRegistry(HWND);

 

function ExFn_RegDBConnectRegistry(hMSI)

    STRING szRemoteMachine, szKey, szTitle, szMsg;

    NUMBER nKeyType, nReturn;

begin

 

    szTitle         = "RegDBConnectRegistry & RegDBDisConnectRegistry";

    szRemoteMachine = REMOTE;

    nKeyType        = HKEY_LOCAL_MACHINE;

    szMsg           = "Setup will now connect to %s.";

    

    SprintfBox (INFORMATION, szTitle, szMsg, szRemoteMachine);

 

    // Connect to the remote computer's registry.  All registry-related

    // function calls will now alter only the remote computer.

    nReturn = RegDBConnectRegistry (szRemoteMachine, nKeyType, 0);

 

    if (nReturn < 0) then

        szMsg = "RegDBConnectRegistry failed.\n\nCould not connect to remote " +

                "system.";

        MessageBox (szMsg, SEVERE);

        abort;

    else

        szMsg = "Successfully connected to %s.";

        SprintfBox (INFORMATION, szTitle, szMsg, szRemoteMachine);

    endif;

 

    // Create a key on the remote computer.

    szKey   = "SOFTWARE\\InstallShield\\Test Key";

    nReturn = RegDBCreateKeyEx(szKey, "");

 

    if (nReturn < 0) then

        szMsg = "RegDBCreateKeyEx failed.\n\n\Could not create key on remote " +

                "machine.";

        MessageBox (szMsg , SEVERE);

    else

        szMsg = "Successfully created %s on %s.";

        SprintfBox (INFORMATION, szTitle, szMsg, szKey, szRemoteMachine);

 

        // Verify that the key now exists in the remote registry.

        nReturn = RegDBKeyExist(szKey);

 

        if (nReturn < 0) then

            szMsg = "RegDBKeyExist failed.\n\nRemote key does not exist.";

            MessageBox (szMsg, SEVERE);

        else

            szMsg = "%s exists.";

            SprintfBox (INFORMATION, szTitle, szMsg, szKey);

        endif;

    endif;

 

    // Delete the key that was created on the remote computer.

    nReturn = RegDBDeleteKey(szKey);

 

    if (nReturn < 0) then

        MessageBox("RegDBDeleteKey failed.\n\nRemote key could not be deleted.",

                  INFORMATION);

    else

        szMsg = "Successfully deleted %s on %s.";

        SprintfBox(INFORMATION, szTitle, szMsg, szKey, szRemoteMachine);

    endif;

 

    // Disconnect from the remote registry.  All registry-related functions

    // will now alter only the local registry.

    nReturn = RegDBDisConnectRegistry(0);

 

    if (nReturn < 0) then

        MessageBox("RegDBDisConnectRegistry failed.\n\nRemote registry still " +

                  "connected.", SEVERE);

    else

        MessageBox("RegDBDisConnectRegistry successful.\n\nRemote registry " +

                  "disconnected.", INFORMATION);

    endif;

 

end;