Navigation: For Developers > Extend Functionality with HEScript > Sample Scripts >

How to run an executable file or app?

 

 

 

 

This comprehensive tutorial on How to Execute an External Program or a Program Embedded within your HTML Executable Publication will walk you through these processes in a clear and concise manner. Let's get started!

 

Running 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.

 

Here's an example script:

 

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

 

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.

 

Running 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;
var
 MyProgram: String;
begin
 MyProgram := UnpackTemporaryResource("programfilename.exe");
 RunAProgram(MyProgram, "", ExtractFilePath(MyProgram), false, SW_SHOWNORMAL);
end;

 

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.