How Do I Run an EXE File not located in the same folder?

zr11

New member
I would like to Run a Program lets call it myProgram.exe when a user clicks on a link in the compiled html ebook. It will run from a cd rom so the path of the ebook lets call that theeBook.exe will change depending on a users computer settings and drive letters.

theeBook.exe will be in the root/main folder of the cd and myProgram.exe will be in a relative subfolder called BIN . I have tried using the Macros that come with htmlexe. I have tried both the MacroExecuteProgram as follows:

and I have tried the MacroOpenFile as follows:

Can someone PLEASE tell me how to get this to work! Thanks so much in advance!
 
Last edited:
I suggest that you follow the instructions at http://www.htmlexe.com/wiki/ExternalPrograms

In your case, the script to use would be:
Code:
procedure OpenAnExternalProgram;
var
 EbookPath, MyProgram: String;
begin
 // Read the path to the folder that contains our ebook .exe
 EbookPath := GetGlobalVar("HEPublicationPath", "");
 // Construct the path to the .exe file we want to launch.
 MyProgram := EbookPath + "BIN\myProgram.exe";
 // Execute the program!
 if not RunAProgram(MyProgram, "", EbookPath, false, SW_SHOWNORMAL) then
 begin
  MessageBox("Unable to execute the external program : " + MyProgram, "Ebook Error", MB_OK+MB_ICONERROR);
  exit;
 end;
end;
 
Last edited:
That is fine for this example I suppose but I need a script that I can pass parameters to so I can use it for a few different links without having to write a new specific script each time around! What I really need to be able to do is simply pass the filename with the relative path. That is why the macro script as was worked except for the problem with passing the path. Passing the Filename alone i.e “myProgram.exe” works, but if the file is in a subdirectory and needed to be passed as “subdirectory\myProgram.exe” the script breaks.

I like the code you provided as is provides some error handling, but what would it look like to add the ability to pass the file with path as opposed to hard coding the file name information.
 
Last edited:
I just found another issue with the example script you provided. Under Windows 7 64 bit the only way the EXE will launch and not produce the “Unable to execute the external program” error and do nothing, is if you right click and Run the ebook exe as Administrator. The funny thing is that if you use the Macros Open File Script, you do not need to right click open as Administrator. Is there a solution of fix for this issue?
 
Last edited:
The problem with passing a relative path is due to the “” character. If you use a messagebox to show the value of the parameter, you’ll see that the “” character is changed into “/”. You should try to insert the correct character again using the ReplaceString function.
The “Run as administrator” problem can be solved: replace RunAProgram by OpenFile.
 
Last edited:
Could you please give me an example using the Replace String Function to accomplish this task. It seems simple enough but has caused me a lot of headache! Has this been addressed in version 4. If so then maybe I will just upgrade now, but I need a fix to this ASAP!
 
Last edited:
Back
Top