我循环调用ShellExecute(".exe",""), for int i:=0 to 10 do begin ShellExecute(".exe","",""); End; 因为我的exe文件里面会有运行Cmd的命令,所以每次ShellExecute就会有cmd的窗体弹出来,有什么办法等一个exe完全运行完毕再进行下一个ShellExecute的操作?
class function SynchroExecute(const AExecutedFileName: string;
const AWaitTime: Integer; const AIsShow: Boolean): Boolean;
var
stinfo:TStartupInfo;
psinfo:TProcessInformation;
sap,sat:TSecurityAttributes;
begin
Result:=False;
stinfo.dwFlags:=STARTF_USESHOWWINDOW;
stinfo.cbReserved2:=0;
stinfo.lpReserved:=nil;
stinfo.lpReserved2:=nil;
stinfo.lpDesktop:=nil;
if not AIsShow then
stinfo.wShowWindow:=SW_HIDE
else
stinfo.wShowWindow:=SW_SHOWNORMAL;
stinfo.cb:=SizeOf(TStartupInfo);
if FileExists(AExecutedFileName) and
CreateProcess(PChar(AExecutedFileName),'',@sap,@sat,False,NORMAL_PRIORITY_CLASS,nil,PChar(ExtractFilePath(ExpandFileName(AExecutedFileName))),stinfo,psinfo) then
begin
CloseHandle(psinfo.hThread);
Result:=WaitForSingleObject(psinfo.hProcess,AWaitTime) = WAIT_OBJECT_0;
CloseHandle(psinfo.hProcess);
end
else begin
RaiseLastOSError;
end;
end;