Running a bat script when exiting (closing) an application

app-user

Member
Hello!

Could you please advise how to make a bat script execute (preferably in the background without displaying) when exiting (closing) an application?

RunAProgram(GetGlobalVar("HEPublicationPath", "") + "test.bat", "", GetGlobalVar("HEPublicationPath", ""), SW_SHOWNORMAL, true); — doesn't work.

Thank you.
 
Solution
Hello!

Could you please advise how to make a bat script execute (preferably in the background without displaying) when exiting (closing) an application?

RunAProgram(GetGlobalVar("HEPublicationPath", "") + "test.bat", "", GetGlobalVar("HEPublicationPath", ""), SW_SHOWNORMAL, true); — doesn't work.

Thank you.
RunAProgram expects an EXE file. A batch file is not an EXE file. For batch files, you can try OpenFile:


OpenFile Opens an external document or program file.

function OpenFile(const Filename, Parameters: String; State: Integer): Integer;
* Filename: full path to the file you want to open or run.
* Parameters: optional command line parameters.
* State: window...
Looking at the help docs, this may help you. To open docs, start a project and look for the blue icon ? at top right.

PHP's exec(), shell_exec() and system() commands are supported in apps made with ExeOutput for PHP.

The following PHP code illustrates how to use them to run external EXE files, BAT (batch) files, and so on. By default, a console window is shown.

Run a batch file in the same folder as the app's EXE file. In this sample, the exo_getglobalvariable PHP function returns the path to the folder where the EXE lies.

Code:
<?php

$mypath = exo_getglobalvariable('HEPublicationPath', '').'sample.bat';

echo exec($mypath);

?>

For a console application, use:

Code:
<?php

system('cmd /c "'.dirname(__DIR__) . '\\test.bat"');

?>
 
Hello!

Could you please advise how to make a bat script execute (preferably in the background without displaying) when exiting (closing) an application?

RunAProgram(GetGlobalVar("HEPublicationPath", "") + "test.bat", "", GetGlobalVar("HEPublicationPath", ""), SW_SHOWNORMAL, true); — doesn't work.

Thank you.
RunAProgram expects an EXE file. A batch file is not an EXE file. For batch files, you can try OpenFile:


OpenFile Opens an external document or program file.

function OpenFile(const Filename, Parameters: String; State: Integer): Integer;
* Filename: full path to the file you want to open or run.
* Parameters: optional command line parameters.
* State: window state. May be SW_SHOWNORMAL, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED, SW_HIDE…
* Result: successful if greater than 31.

For executable files, you may also use RunAProgram.

Code:
OpenFile(GetGlobalVar("HEPublicationPath", "") + "test.bat", "", SW_SHOWNORMAL);

And to execute when the app closes, in the UserMain HEScript of your project, locate:

procedure OnPubBeingClosed;

and add:

Code:
procedure OnPubBeingClosed;
begin
OpenFile(GetGlobalVar("HEPublicationPath", "") + "test.bat", "", SW_SHOWNORMAL);
end;

To add HEScript code to an event, see:
 
Solution
Back
Top