copy过来的,你看能用不能用。{ ----------------------------------------------------- }
{调用其他程序并等待                                    }
{ ----------------------------------------------------- }
function TMainForm.WinExecAndWait32(FileName: string;
  Visibility: integer): integer;
var
  zAppName: array[0..512] of char;
  zCurDir: array[0..255] of char;
  WorkDir: string;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  ExecResult: DWORD;
begin
  StrPCopy(zAppName, FileName);
  GetDir(0, WorkDir);
  StrPCopy(zCurDir, WorkDir);
  FillChar(StartupInfo, Sizeof(StartupInfo), #0);
  StartupInfo.cb := Sizeof(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  if not CreateProcess(nil,
    zAppName, { pointer to command line string }
    nil, { pointer to process security attributes }
    nil, { pointer to thread security attributes }
    false, { handle inheritance flag }
    CREATE_NEW_CONSOLE or { creation flags }
    NORMAL_PRIORITY_CLASS,
    nil, { pointer to new environment block }
    nil, { pointer to current directory name }
    StartupInfo, { pointer to STARTUPINFO }
    ProcessInfo) then Result := -1 { pointer to PROCESS_INF }
  else begin
    //Application.Minimize;
    ShowWindow(Application.Handle, SW_HIDE);
    WindowState := wsMinimized;
    Enabled := false;
    WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, ExecResult);
    Result := ExecResult;
    Enabled := true;
    WindowState := wsMaximized;
    ShowWindow(Application.Handle, SW_SHOWNORMAL);
    BringToFront;
    Application.BringToFront;
    SetFocus;
  end;
end;