CreateShortcut Example 2

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 CreateShortcut function.

*

* This example creates a cascading submenu on the Startup menu

* and adds a shortcut for an executable file to it.

*

* Note: Before running this script, set the preprocessor

*       constants so that they reference the fully qualified

*       names of the Windows Notepad executable file and a

*       valid text file on the target system.

*

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

 

#define PROGRAM "C:\\Windows\\Notepad.exe"

#define PARAM   "C:\\Windows\\Readme.txt"

 

function OnFirstUIAfter()

    STRING  szShortcutFolder, szName, szCommandLine, szWorkingDir;

    STRING  szIconPath, szShortCutKey, szProgram, szParam;

    NUMBER  nIcon, nFlag, nResult;

begin

 

    // Set the fully qualified name of the Startup submenu.

    szShortcutFolder = FOLDER_STARTUP ^ "SubMenu Example";

 

    // Construct the shortcut’s command-line property.

    szProgram  = PROGRAM;

    szParam    = PARAM;

 

    LongPathToQuote (szProgram, TRUE);

 

    LongPathToShortPath (szParam);

 

    szCommandLine = szProgram + " " + szParam;

 

    // Set up the shortcut’s other properties to pass to CreateShortcut.

    szName        = "Notepad Example2";

    szWorkingDir  = "";

    szIconPath    = "";

    nIcon         = 0;

    szShortCutKey = "";

    nFlag         = CS_OPTION_FLAG_REPLACE_EXISTING|CS_OPTION_FLAG_RUN_MAXIMIZED;

 

    // Add the shortcut to the submenu; create the submenu if necessary.

    nResult = CreateShortcut (szShortcutFolder, szName, szCommandLine,

                              szWorkingDir, szIconPath, nIcon,

                              szShortCutKey, nFlag);

 

    // Report the results.

    if (nResult < 0) then

        MessageBox ("CreateShortcut failed.", SEVERE);

    else

        SprintfBox (INFORMATION, "CreateShortcut", "%s created successfully.",

                   szName);

    endif;

 

end;