下面这个函数调用外部程序,执行完毕后才返回真。
function Run(sCommandLine: string): Boolean
//Time out when 1 hour elapsed
var
lpStartupInfo: TStartupInfo;
lpProcessInformation: TProcessInformation;
begin
FillChar(lpStartupInfo, Sizeof(TStartupInfo), #0);
lpStartupInfo.dwFlags := STARTF_USESHOWWINDOW;
lpStartupInfo.wShowWindow := SW_SHOW;
Result := CreateProcess(nil, PChar(sCommandLine),
nil, nil, True, NORMAL_PRIORITY_CLASS, nil, nil,
lpStartupInfo, lpProcessInformation) and
(WaitForSingleObject(lpProcessInformation.hProcess, 3600000) <> WAIT_FAILED);
end;