AskPath Example

InstallShield 2016 » InstallScript Language Reference

Project • This information applies to the following project types:

InstallScript
InstallScript MSI

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

*

* InstallShield Example Script

*

* Demonstrates the AskPath function.

*

* This script obtains the path to a folder on the

* end user's computer.  If the path does not exist, it creates

* a folder at that location if indicated by the

* end user.  Finally, it displays the selected path.

*

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

 

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

#include "Ifx.h"

 

export prototype ExFn_AskPath(HWND);

 

function ExFn_AskPath(hMSI)

    STRING szMsg, svResultPath[101];

    BOOL bTargetDirOk;

begin

 

    // Disable the Back button in installation dialogs.

    Disable (BACKBUTTON);

 

    // Create the message to display in the AskPath dialog.

    szMsg = "Specify a folder for the application.";

 

    // Initialize valid path indicator.

    bTargetDirOk = FALSE;

 

    repeat

        // Get a path from the user.  The default path is

        // the current value of the system variable INSTALLDIR.

        if (AskPath (szMsg, INSTALLDIR, svResultPath) = NEXT) then

            // Does the path entered by the user exist on the

            // target system?

            if (ExistsDir (svResultPath) = 0) then

                // If it exists, set indicator to exit the loop.

                bTargetDirOk = TRUE;

            else

                // If the path doesn't exists, ask if it should be created.

                 if (AskYesNo ("Folder does not exist. Create it?",YES) = YES) then

                    // Attempt to create the folder (directory).

                    if (CreateDir (svResultPath) = 0) then

                        // If the folder was created, set indicator to exit the loop.

                        bTargetDirOk = TRUE;

                    else

                        // Inform the end user that the folder was not created.

                        MessageBox ("Unable to create " + svResultPath, WARNING);

                    endif;

                endif;

            endif;

        endif;

    until bTargetDirOk;

 

    // Display the name of the target folder.

    MessageBox ("The target folder is " + svResultPath, INFORMATION);

 

    // You'd also enable the Back button for subsequent dialogs.

    Enable (BACKBUTTON);

 

end;