//执行程序并等待其结束
Function WinExecExW(cmd,workdir:pchar;visiable:integer):DWORD;
var
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
ret:DWORD;
begin
FillChar(StartupInfo,SizeOf(StartupInfo),#0);
StartupInfo.cb:=SizeOf(StartupInfo);
StartupInfo.dwFlags:=STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow:=visiable;
Application.ProcessMessages;
if not CreateProcess(nil,cmd,nil,nil,false,Create_new_console or Normal_priority_class,nil,nil,StartupInfo,ProcessInfo) then
result:=0
else
begin
Application.ProcessMessages;
//waitforsingleobject(processinfo.hProcess,INFINITE);
repeat
ret:=WaitforSingleObject(ProcessInfo.hProcess,100); //等待
Application.ProcessMessages;
until ret <> Wait_Timeout;
GetExitCodeProcess(ProcessInfo.hProcess,Result);
end;
end;
联系客服