LongPathToShortPath 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 functions LongPathToShortPath and

* LongPathFromShortPath.

*

* First, LongPathToShortPath is called to convert a long path

* to a short path.  Then LongPathFromShortPath is called to

* convert the short path to a long path.  The result of each

* is displayed in a message box.

*

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

 

#define LONG_PATH "C:\\Program Files"

#define TITLE "LongPathToShortPath & LongPathFromShortPath"

 

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

#include "Ifx.h"

 

export prototype ExFn_LongPathToShortPath(HWND);

 

function ExFn_LongPathToShortPath(hMSI)

   STRING svPath, szTitle, szMsg;

begin

 

    // Prompt user to enter a long path.

    szMsg    = "Please select an existing long path:";

    AskPath (szMsg, LONG_PATH, svPath);

 

    // Display the long path.

    szMsg = "The long path is shown below: \n\n%s";

    SprintfBox (INFORMATION, TITLE, szMsg, svPath);

 

    //Convert the long path to a short path.

    if (LongPathToShortPath (svPath) < 0) then;

        MessageBox ("LongPathToShortPath failed.", SEVERE);

        abort;

    else

        // Display the short path.

        szMsg = "The short path is shown below: \n\n%s";

        SprintfBox (INFORMATION, TITLE, szMsg, svPath);

    endif;

 

    // Restore the long path from the short path.

    if (LongPathFromShortPath (svPath) < 0) then

        MessageBox ("LongPathFromShortPath failed.", SEVERE);

    else

        // Display the restored long path.

        szMsg = "The restored long path is shown below: \n\n%s";

        SprintfBox (INFORMATION, TITLE, szMsg, svPath);

    endif;

 

end;