如何判断外部应用程序何时以delphi结尾 [英] how to tell when an external application ends in delphi
本文介绍了如何判断外部应用程序何时以delphi结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用ShellExecute运行外部应用程序我如何知道外部应用程序何时结束?
I am using ShellExecute to run external application How can i tell when the external application ends ?
这是我的代码
theProgram := 'MySql.exe';
itsParameters := ' -u user1 -ppassword -e "create database abc"’;
rslt := ShellExecute(0, 'open',
pChar (theProgram),
pChar (itsParameters),
nil,
SW_SHOW);
推荐答案
尝试以下功能.WaitForSingleObject可以满足您的需求.
Try the following function. WaitForSingleObject does what you need.
function ExecAppAndWait(const sApp, sParams: String; wShow: Word; sCurrentDirectory: String = ''): DWord;
{ Parameter wShow: SW_HIDE, SW_SHOWNORMAL, SW_NORMAL, SW_MAXIMIZE ...}
var
aSI : TStartupInfo; // Win32 : STARTUPINFO
aPI : TProcessInformation; // Win32 : PROCESS_INFORMATION
aProc : THandle; // Win32
aCurrentDirectory: PChar;
s: String;
begin
s := sApp + ' ' + sParams;
FillChar(aSI, SizeOf(aSI), 0);
aSI.cb := SizeOf(aSI);
aSI.wShowWindow := wShow;
aSi.dwFlags := STARTF_USESHOWWINDOW;
if sCurrentDirectory = '' then
aCurrentDirectory := nil
else
aCurrentDirectory := PChar(sCurrentDirectory);
Win32Check(CreateProcess(nil, PChar(s), nil, nil,
False, Normal_Priority_Class, nil, aCurrentDirectory, aSI, aPI));
// in TProcessInformation.hProcess -> Process-Handle
aProc := aPI.hProcess;
CloseHandle(aPI.hThread);
if WaitForSingleObject(aProc, Infinite) <> Wait_Failed then
GetExitCodeProcess(aProc, Result);
// free Ressource
CloseHandle(aProc);
end;
这篇关于如何判断外部应用程序何时以delphi结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文