function WinExecAndWait32(FileName: string; Visibility: Boolean): integer;stdcall;<br>var<br> zAppName: array[0..512] of char; //存放应用程序名<br> StartupInfo: TStartupInfo;<br> ProcessInfo: TProcessInformation;<br> exitCode: Dword;<br> aVisibility: integer;<br>begin<br> try<br> StrPCopy(zAppName, FileName);<br> FillChar(StartupInfo, Sizeof(StartupInfo), #0);<br> //给StartupInfo结构体赋值<br> StartupInfo.cb := Sizeof(StartupInfo);<br> StartupInfo.dwFlags := STARTF_USESHOWWINDOW;<br> if Visibility then<br> aVisibility := 1<br> else<br> aVisibility := 0;<br><br> StartupInfo.wShowWindow := aVisibility;<br> //调用CreateProcess 创建进程,执行指定的可执行文件<br> if not CreateProcess(nil, zAppName, nil, nil, false<br> , CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS<br> , nil, nil, StartupInfo, ProcessInfo) then<br> Result := -1<br> else<br> begin<br> //等待可执行文件退出<br> WaitforSingleObject(ProcessInfo.hProcess, INFINITE);<br> //得到进程终止状态码<br> GetExitCodeProcess(ProcessInfo.hProcess, exitCode);<br> result := Exitcode;<br> end;<br>end;<br><br>WinExecAndWait32(filename,True);//filename 文件路径名+.exe名