http://www.delphibbs.com/delphibbs/dispq.asp?lid=1421799
xlzps 大虾的代码
function CreateProcessAndWait(const AppParams: String; Visibility: word;
var d: DWord): Boolean;
var
SI: TStartupInfo;
PI: TProcessInformation;
Proc: THandle;
begin
FillChar(SI, SizeOf(SI), 0);
SI.cb := SizeOf(SI);
SI.wShowWindow := Visibility;
result := true;
if not CreateProcess(nil, PChar(AppParams), Nil, Nil, False,
Normal_Priority_Class, Nil, Nil, SI, PI) then
begin
result := false;
raise Exception.CreateFmt('Failed to execute program. Error Code %d',
[GetLastError]);
end;
Proc := PI.hProcess;
CloseHandle(PI.hThread);
if WaitForSingleObject(Proc, Infinite) <> Wait_Failed then
GetExitCodeProcess(Proc, d);
CloseHandle(Proc);
end;