How to run an executable program?

This script illustrates how to run an external program or a program that was compiled inside your publication. For instance, you would like to launch a program that you ship with your publication.

Run an external program file

We use the internal HEScript function named RunAProgram to execute a program. We only need to know the path to the program file we want to launch. Fortunately HTML Executable has a global variable named HEPublicationPath pointing to the path of the folder that contains the publication’s exe file.

Script example:

procedure RunTutor;
EbookPath, MyProgram: String;
EbookPath := GetGlobalVar("HEPublicationPath", "");
MyProgram := EbookPath + "hehvdemo.exe";
RunAProgram(MyProgram, "", EbookPath, false, SW_SHOWNORMAL);

First we get the path to our publication stored into the EbookPath variable. Then we add the filename of our executable program and we pass the result to the RunAProgram function.

Test this script!

Run a program that was compiled in the publication

You can include the program file directly into your publication .exe. In that case you need to extract the program file before running it: use the _heopenit target or the following code:

procedure RunACompiledProgram;
MyProgram: String;
MyProgram := UnpackTemporaryResource("programfilename.exe");
RunAProgram(MyProgram, "", ExtractFilePath(MyProgram), false, SW_SHOWNORMAL);

This code uses the UnpackTemporaryResource internal function that extracts a compiled file from the publication to a temporary location. Then you just need to execute the file.

Introduction to Scripting

Using the Script Manager

Script Function Reference

Copyright G.D.G. Software 2019. All rights reserved