External Application


If I wanted to launch an external EXE application from my application how would I do it?  
aj85Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

spatCommented:
var
  cmd := 'C:\SNDvol32.exe';
begin
  if WinExec(@cmd[1],5) < 32 then
     messageDlg(Unable to open this program', mtError, [mbOk], 0);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.