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

*

* QueryProgItem is called to find the attributes of a target

* file or folder.

*

* Note: Before running this script, set the defined constants

*       FOLDER_NAME and ITEM_NAME so that they reference an

*       existing folder name and folder item.

*

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

// Define constants to reference the file or folder name.

#define FOLDER_NAME  "C:\\Windows\\Start Menu\\Programs"

#define ITEM_NAME    "InstallShield"

 

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

#include "Ifx.h"

 

    export prototype ExFn_QueryProgItem(HWND);

 

function ExFn_QueryProgItem(hMSI)

    STRING   svCmdLine, svWrkDir, svIconPath;

    STRING   svShortCutKey, svGroupPath, szTitle, szMsg, szInfo, svMinFlag;

    STRING   svMinimizeFlag;

    NUMBER   nvIconIndex, nvMinimizeFlag, nResult, nvMinFlag;

    LIST     listInfo, listID;

begin

 

    // Search for an item in the FOLDER_NAME folder.

    nResult = QueryProgItem (FOLDER_NAME, ITEM_NAME, svCmdLine, svWrkDir,

                            svIconPath, nvIconIndex, svShortCutKey,

                            nvMinimizeFlag);

    

    // Create string list.

    listInfo = ListCreate (STRINGLIST);

        

    // Error check QueryProgItem.

    if (nResult < 0) then

        // Report the error; then abort.

        MessageBox("QueryProgItem failed.", SEVERE);

        abort;

    // Check if the item is an application.

    elseif (nResult = IS_ITEM) then

        // Add the command line to the string list.

        Sprintf(szInfo, "The command line of %s: %s", ITEM_NAME, svCmdLine);

        ListAddString(listInfo, szInfo, AFTER);

 

        // Add the working directory to string list.

        Sprintf(szInfo, "The working directory of %s: %s", ITEM_NAME, svWrkDir);

        ListAddString(listInfo, szInfo, AFTER);

    

        // Add the icon path to string list.

        Sprintf(szInfo, "The icon path of %s: %s", ITEM_NAME, svIconPath);

        ListAddString(listInfo, szInfo, AFTER);

    

        // Add icon index to string list.

        Sprintf(szInfo, "The index of the icon: %d", nvIconIndex);

        ListAddString(listInfo, szInfo, AFTER);

    

        // Add shortcut key to string list.

        Sprintf (szInfo, "The shortcut key of %s: %s", ITEM_NAME,

                svShortCutKey);

        ListAddString(listInfo, szInfo, AFTER);

    

        // Check if the item is a folder.

    elseif (nResult = IS_FOLDER) then

        // Add a message to string list.

        Sprintf (szInfo, "The item is a subfolder.  QueryProgItem does not " +

                "retrieve very much information about subfolders.");

        ListAddString(listInfo, szInfo, AFTER);

    endif;

    

    // Display the string list.

    szTitle = "QueryProgItem Example";

    szMsg   = "The following are attributes of the item:";

    SdShowInfoList(szTitle, szMsg, listInfo);

    

    // Destroy the list.

    ListDestroy (listID);

 

end;