View Categories

How to Run an Executable Program

1 min read

This guide illustrates how to run an external program or a program compiled into your application. For instance, you may want to launch a program that you ship with your application.

Running an External Program File #

Use the internal RunAProgram HEScript function to execute a program. You only need the path to the program file you want to launch. Fortunately, ExeOutput for PHP provides a HEPublicationPath global variable that points to the folder containing the application’s EXE file.

Script Example:

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 application and store it in the EbookPath variable. Then, we append the filename of our executable and pass the resulting path to the RunAProgram function.

Running a Program Compiled into the Application #

You can include program files directly into your application’s EXE. In that case, you need to extract the program file before running it. You can use the heopenit special protocol 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 to extract a compiled file to a temporary location. Then, you can execute the file.

Introduction to Scripting

Using the Script Manager

Script Function Reference

Leave a Reply

Your email address will not be published. Required fields are marked *