AddFolderIcon Example 3

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

*

* This example places a subfolder on the desktop and an icon

* pointing to an executable in the new folder.  The folder is

* a shortcut that points to an actual directory.  From this

* folder the user can execute a shortcut that runs the program.

*

* Note: Before running this script, set the preprocessor

*       constants so that they reference the fully qualified

*       names of the Windows Notepad executable and a valid

*       text file on the target system.

*

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

 

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

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

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

 

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

#include "Ifx.h"

 

export prototype ExFn_AddFolderIcon(HWND);

 

function ExFn_AddFolderIcon(hMSI)

   STRING  szProgramFolder, szItemName, szCommandLine, szWorkingDir;

    STRING  szIconPath, szShortCutKey;

    STRING  szProgram, szParam, szFolderDir;

    NUMBER  nIcon, nFlag, nResult;

begin

 

   // szProgramFolder is the Desktop on the local system.

   szProgramFolder = FOLDER_DESKTOP;

   szItemName      = "Example folder";

 

   // Create the folder which the folder icon will point to.

   szFolderDir = FOLDER ^ szItemName;

   CreateDir(szFolderDir);

 

   // The command line for the folder icon must be the folder path, and

   // it must be enclosed in quotation marks if the path is longer than

   // eight characters.

 

   szCommandLine = szFolderDir;

   LongPathToQuote(szCommandLine, TRUE);

 

   szWorkingDir  = "";

   szIconPath    = "";

   nIcon         = 0;

   szShortCutKey = "";

   nFlag         = REPLACE|RUN_MINIMIZED;

 

   // Create the folder icon, and show the folder it points to.

   nResult = AddFolderIcon (szProgramFolder, szItemName, szCommandLine,

                            szWorkingDir, szIconPath, nIcon, szShortCutKey,

                            nFlag);

 

   if (nResult < 0) then

      MessageBox("AddFolderIcon failed.", SEVERE);

   else

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

                  szItemName);

   endif;

 

   // Display the folder just created.

   ShowProgramFolder (szFolderDir, SW_SHOW);

 

   // Add the Example icon to the newly created folder.

   szProgramFolder = szFolderDir;

   szItemName      = "Notepad Example";

 

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

   szProgram       = PROGRAM;

   LongPathToQuote (szProgram, TRUE);

 

   szParam = PARAM;

   LongPathToShortPath (szParam);

 

   szCommandLine = szProgram + " " + szParam;

   szWorkingDir  = "";

   szIconPath    = "";

   nResult = AddFolderIcon (szProgramFolder, szItemName, szCommandLine,

                            szWorkingDir, szIconPath, nIcon, szShortCutKey,

                           nFlag);

 

   if (nResult < 0) then

      MessageBox ("AddFolderIcon failed.", SEVERE);

   else

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

                 szItemName);

   endif;

 

end;