ReplaceShortcut Example

InstallShield 2016 » 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 ReplaceShortcut function.

*

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

*       preprocessor constants to valid file names and a path

*       on the target system. To easily create this example

*       shortcut, run the CreateShortcut example 3.

*

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

 

#define FOLDER      "C:\\Windows\\"

#define NEW_PROGRAM "C:\\WINDOWS\\WRITE.EXE"

#define NEW_PARAM   "C:\\WINDOWS\\README.TXT"

 

function OnFirstUIAfter()

    STRING szShortcutFolder, szName, szNewItem, szCmdLine, szWorkingDir;

    STRING szIconPath, szShortCutKey, szProgram, szParam;

    NUMBER nIcon, nFlag;

begin

 

    szShortcutFolder = FOLDER ^ "Example folder 3";

    szName           = "Notepad Example 3";

    szNewItem        = "New Wordpad Example";

 

    // Make sure the space is not seen as a delimiter.

    szProgram = NEW_PROGRAM;

    LongPathToQuote (szProgram, TRUE);

 

    szParam = NEW_PARAM;

    LongPathToShortPath(szParam);

 

    szCmdLine      = szProgram + " " + szParam;

    szWorkingDir   = "";

    szIconPath     = "";

    nIcon          = 0;

    szShortCutKey  = "";

    nFlag          = CS_OPTION_FLAG_REPLACE_EXISTING|CS_OPTION_FLAG_RUN_MAXIMIZED;

 

    // Display the folder on the screen.

    ShowProgramFolder (szShortcutFolder, SW_SHOW);

 

    // Replace the Notepad Example 3 shortcut with New Wordpad Example.

    if (ReplaceShortcut (szShortcutFolder, szName, szNewItem, szCmdLine,

                          szWorkingDir, szIconPath, nIcon, szShortCutKey,

                          nFlag) < 0) then

        MessageBox ("ReplaceShortcut failed.", SEVERE);

    else

        MessageBox ("Shortcut successfully replaced.", INFORMATION);

    endif;

 

end;