function WinExecAndWait32(FileName, Params: string;<br> ShowRunForm: Boolean = True): integer;<br>var<br> zAppName: array [0..512] of char;<br> zCurDir: array [0..255] of char;<br> CurDir, WorkDir: string;<br> dwExitCode: DWord;<br> StartupInfo: TStartupInfo;<br> ProcessInfo: TProcessInformation;<br>begin<br> Result := 0;<br> WorkDir := ExtractFilePath(FileName);<br> FileName := FileName + ' ' + Params<br> StrPCopy(zAppName, FileName);<br> GetDir(0, CurDir);<br> StrPCopy(zCurDir, CurDir);<br> dwExitCode := STILL_ACTIVE;<br> FillChar(StartupInfo, Sizeof(TStartupInfo), #0);<br> FillChar(ProcessInfo, SizeOf(TProcessInformation), #0);<br> StartupInfo.cb := Sizeof(StartupInfo);<br> StartupInfo.dwFlags := STARTF_USESHOWWINDOW;<br> if ShowRunForm then<br> StartupInfo.wShowWindow := sw_Normal // 显示 DOS 窗口<br> else<br> StartupInfo.wShowWindow := sw_Hide; // 不显示 DOS 窗口<br> if not CreateProcess(<br> nil, //待执行程序名<br> zAppName, //执行参数<br> nil, //进程安全级别<br> nil, //线程安全级别<br> false, //继承标志<br> DETACHED_PROCESS + //创建标志<br> HIGH_PRIORITY_CLASS,<br> nil, //环境变量,如:"Files=20;"<br> Pointer(WorkDir), //当前路径<br> StartupInfo, //STARTUPINFO 纪录信息<br> ProcessInfo) then Result := 0 //PROCESS_INF 纪录信息<br> else<br> begin<br> if ProcessInfo.hProcess <> 0 then<br> while (dwExitCode = STILL_ACTIVE) do<br> begin<br> WaitForSingleObject(ProcessInfo.hProcess, 50);<br> GetExitCodeProcess(ProcessInfo.hProcess, dwExitCode);<br> end;<br> end;<br>end;<br><br>调用:(假设要调用的程序为 FileNameEdt, 要传的参数放在 ParamEdt1, ParamEdt2)<br><br> WinExecAndWait32(FileNameEdt.Text, ParamEdt1.Text + ' ' + ParamEdt2.Text);<br> ShowMessage('调用完成');<br><br>