You can use ShellExececute WinApi Call,
there is a function called ExecuteFile included with the fmxUtils.pas file.
Below is a function that waits until the program has terminated before
allowing control back to the main program. Also has an example of how to use
CreateProcess - which is another way of Executing a file.
function DOSExec( const ProgName : String;
const Wait : Boolean;
const Visibility : TDOSWindowState;
var Msg : String ) : Boolean;
{ Executes external DOS program with Params. }
{ Visibility is
{ Returns Msg and True/False depending on Success }
{ NOTE - ProgName must include PATH }
var
CmdLine : String;
CmdShow : Integer;
StartupInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
ResultWait : Integer;
ErrorCode : Integer;
Rslt : LONGWORD;
begin
Result := False;
Msg := '';
CmdLine := ProgName;
Case Visibility of
dwMinimized : CmdShow := SW_SHOWMINIMIZED;
dwNormal : CmdShow := SW_SHOWNORMAL;
dwMaximized : CmdShow := SW_SHOWMAXIMIZED;
else
CmdShow := SW_SHOWNORMAL;
end;
FillChar( StartupInfo, sizeof( StartupInfo ), 0 );
with StartupInfo do begin
cb := sizeof( StartupInfo );
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := CmdShow;
end;
Result := CreateProcess( Nil, PChar( CmdLine ),Nil, Nil, False,
NORMAL_PRIORITY_CLASS, Nil, Nil,
StartupInfo, ProcessInfo );
If not Result then begin
ErrorCode := GetLastError;
Msg := Format( 'Create Process Error %d', [ ErrorCode ] );
Exit;
end;
Application.ProcessMessages;
if Wait then begin
Repeat
// Wait for External Process but give App Repaint time etc every
100ms
ResultWait := WaitforSingleObject(ProcessInfo.hProcess,100);
Application.ProcessMessages;
GetExitCodeProcess(ProcessInfo.hProcess, Rslt);
Until not ( Rslt = STILL_ACTIVE );
end;
CloseHandle( ProcessInfo.hProcess );
CloseHandle( ProcessInfo.hThread );
end;
-----Original Message-----
From: Leo Ramakers [mailto:[EMAIL PROTECTED]]
Sent: Friday, 21 July 2000 11:10
To: Multiple recipients of list delphi
Subject: [DUG]: How to execute a windows program from within an
application
{a Slight variation to Brett Lins question}
How can I call a windows program from within an application. I vaguely
recall it used to be something like
begin
execute('c:\path\myprog.exe param1 param2').
end;
best regards
Leo
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
CAUTION - This message may contain privileged and confidential information intended
only for the
use of the addressee(s) named above. If you are not the intended recipient of this
message you are
hereby notified that any use, dissemination, distribution or reproduction of this
message is prohibited.
If you have received this message in error please notify Progressive Enterprises Ltd.
immediately via
email at [EMAIL PROTECTED] Any views expressed in this message
are those of the
individual sender and may not necessarily reflect the views of Progressive Enterprises
Ltd.
This footnote also confirms that Progressive Enterprises Ltd. has swept this email
message for the
presence of computer viruses. This does not guarantee this message is virus free.
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz