luf
asked on
Run Other Program?
How to run the other program or EXE file in my Application? The program do not infect my Application.
shellexecute will work, but I tought using CreateProcess is better, at least it gives some more functionality. Check Delphi help and previous answer in this group containing an example.
From help:
"The WinExec function runs the specified application.
This function is provided for compatibility with earlier versions of Windows. For Win32-based applications, use the CreateProcess function."
Floris.
From help:
"The WinExec function runs the specified application.
This function is provided for compatibility with earlier versions of Windows. For Win32-based applications, use the CreateProcess function."
Floris.
Hmm.. Perhaps you should read your comment again floris!
Cheers,
Raymond.
Cheers,
Raymond.
What is wrong with using ShellExecute, I use it for a long time...
Motaz
Motaz
yeah, what's wrong with shellexecute?
(I don't know)...
rwilson, the English or the content?
F.
(I don't know)...
rwilson, the English or the content?
F.
I think you must use CreateProcess to track termination of executed application, but if you do not care about termination of executed exe's you can use ShellExecute
Motaz
Motaz
Hi Motaz,
you can also use ShellExecuteEx if you need to wait for the termination of the process after starting it.
Regards, Madshi.
you can also use ShellExecuteEx if you need to wait for the termination of the process after starting it.
Regards, Madshi.
Floris: Its just that your comment seems to treat ShellExecute = WinExec (which it isn't).
Actually WinExec is now just a wrapper for ShellExecute...
Hmm... ;-]
Cheers,
Raymond.
Actually WinExec is now just a wrapper for ShellExecute...
Hmm... ;-]
Cheers,
Raymond.
hey dont forget ExecuteFile()
(add to uses "fmxutils")
:-)
(add to uses "fmxutils")
:-)
Hmmm.
?-)
?-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
just some advice to nicola65
please only leave comments if other people have left comment as motaz answered this with his first comment and it is unfair to propose your comment as the answer.
just makes for a friendlier environment ;-)
please only leave comments if other people have left comment as motaz answered this with his first comment and it is unfair to propose your comment as the answer.
just makes for a friendlier environment ;-)
Hi luf,
Here is the function I use in my app's.
I see Nicola's function is very similar, but the similarity is ocasional (I think) because I have answered this question 2 times before and the answer was the same :-).
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(Start Info);
FillChar(StartInfo, SizeOf(StartInfo), 0);
StartInfo.dwFlags:=STARTF_ USESHOWWIN DOW;
StartInfo.wShowWindow:=Sho wMode;
if AppName<>''
then CreateProcess(PChar(APPNam e), 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(ProcIn fo.hProces s, INFINITE);
GetExitCodeProcess(ProcInf o.hProcess , Result);
end;
Jo.
Here is the function I use in my app's.
I see Nicola's function is very similar, but the similarity is ocasional (I think) because I have answered this question 2 times before and the answer was the same :-).
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(Start
FillChar(StartInfo, SizeOf(StartInfo), 0);
StartInfo.dwFlags:=STARTF_
StartInfo.wShowWindow:=Sho
if AppName<>''
then CreateProcess(PChar(APPNam
nil, nil, StartInfo, ProcInfo)
else CreateProcess(nil, PChar(CmdLine), nil, nil, False, 0,
nil, nil, StartInfo, ProcInfo);
if WaitToExit then WaitForSingleObject(ProcIn
GetExitCodeProcess(ProcInf
end;
Jo.
Hi Fatman, please don't forget to close the handles!!
CloseHandle(ProcInfo.hProc ess);
CloseHandle(ProcInfo.hThre ad);
Regards, Madshi.
CloseHandle(ProcInfo.hProc
CloseHandle(ProcInfo.hThre
Regards, Madshi.
Thanks, Madshi!
Y're right, as ever ;-)
Jo.
Y're right, as ever ;-)
Jo.
If you want to run any application or open any document use ShellExecute:
ShellExecute(handle, 'open', FileName, nil, nil, 0);
do not miss to include ShellApi in your uses clause
Motaz