External Application


If I wanted to launch an external EXE application from my application how would I do it?  
aj85Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
spatConnect With a Mentor Commented:
var
  cmd := 'C:\SNDvol32.exe';
begin
  if WinExec(@cmd[1],5) < 32 then
     messageDlg(Unable to open this program', mtError, [mbOk], 0);
0
 
SmillyCommented:
ShellExecute(Application.Handle,'Open',PChar('program.exe'),nil,nil,SW_SHOW);

Remember to use ShellApi in the uses case.

Smilly
0
 
aj85Author Commented:


This does'nt work with windows my app still runs and does not execute the other app.

Example: //      ShellExecute(Application.Handle,'Open',PChar('gfis.exe' + ' ' + (FWorkID)),nil,nil,SW_SHOW)
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
aj85Author Commented:

What I need to do is pass the command to execute the program and the directory it is in( example: c:\fcis\gfis\gfis.exe).  Then append a value to that (example: 12345), this will be the value the program is looking for.  The example provided I think should work, however, when I coded it and put the SHELLAPI in my uses case, it did nothing except bring me back to my original form.  Also, what do I do to return to my application?  I really need to get an answer to this that works, so I am going to increase my points.


Thanks
TJ
0
 
wimmeyvaertCommented:
Hello aj85,

Maybe you can install the Rx-Library.
This is a set of must-have components
(Freeware + full source-code).

Site : http://www.rxlib.com

After installing those components, you can use the Rxunit-files, which come with these components. One of these unit-files is called RxShell.pas

You have to include this file in your code (uses RxShell).

Then, in your code you can use the Rx-Function :
  FileExecute(const FileName, Params, StartDir: string;
  InitialState: TExecState): THandle;

Example:
  FileExecute('NotePad','File.txt','C:\Working\Directory',esNormal);


I think this should do the trick.

Best regards

The Mayor
0
 
MadshiCommented:
You must give in the right path, and you should use SW_SHOWNORMAL:

ShellExecute(Application.Handle,'Open',PChar('c:\fcis\gfis\gfis.exe' + ' ' + FWorkID), nil, nil, SW_SHOWNORMAL);

Regards, Madshi.
0
 
Fatman121898Commented:
Hi aj85,

I use this function for many times and it works for me fine. Try it.

function ExecApplication(APPName, CmdLine: String; ShowMode: DWord; WaitToExit: Boolean): DWord;
//executes as well WIN and DOS application
  var StartInfo: TStartupInfo;
      ProcInfo: TProcessInformation;
  begin
    StartInfo.cb:=SizeOf(StartInfo);
    FillChar(StartInfo, SizeOf(StartInfo), 0);
    StartInfo.dwFlags:=STARTF_USESHOWWINDOW;
    StartInfo.wShowWindow:=ShowMode;
    if AppName<>''
      then CreateProcess(PChar(APPName), PChar(CmdLine), nil, nil, False, 0,
                         nil, nil, StartInfo, ProcInfo)
      else CreateProcess(nil, PChar(CmdLine), nil, nil, False, 0,
                         nil, nil, StartInfo, ProcInfo);
      if WaitToExit then WaitForSingleObject(ProcInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcInfo.hProcess, Result);
  end;
----------------
Parameter ShowMode has to be one of following:
  SW_HIDE
  SW_MINIMIZE
  SW_MAXIMIZE
   
Hope helps.
Jo.
0
 
aj85Author Commented:

Very clear and straight forward answer, it took care of my problem.  The points are yours....


Thanks!
TJ
0
All Courses

From novice to tech pro — start learning today.