这些东西可能有用<br><br>1. 如何执行外部程序[并一直等到它结束]<br><br>㈠ 编程语言Delphi 1.0,操作系统 Window3.1<br><br>以下是一个执行外部程序ARJ.EXE的例子的部分代码。<br><br>var<br> sCommandLine: string;<br> bCreateProcess: boolean;<br> lpStartupInfo: TStartupInfo;<br> lpProcessInformation: TProcessInformation;<br>begin<br> sCommandLine := 'ARJ.EXE /?';<br> bCreateProcess := CreateProcessA(nil, PChar(sCommandLine),<br> nil, nil, True, NORMAL_PRIORITY_CLASS, nil, nil,<br> lpStartupInfo, lpProcessInformation);<br> if bCreateProcess then<br> WaitForSingleObject(lpProcessInformation.hProcess, INFINITE);<br>end;<br><br>㈡ 编程语言Delphi3.0,操作系统 Window95 <br>同样是上面的例子的部分代码 <br>var<br> pWindowsList: pointer;<br> hActiveWindow: HWnd;<br> hExeHandle: THandle;<br>begin<br> pWindowsList := DisableTaskWindows(0);<br> hActiveWindow := GetActiveWindow;<br> try<br> hExeHandle := WinExec('arj.exe /?',SW_SHOWNORMAL);<br> while GetModuleUsage(hExeHandle) <> 0 do<br> Application.ProcessMessages;<br> finally<br> EnableTaskWindows(pWindowsList);<br> SetActiveWindow(hActiveWindow);<br> end;<br>end;<br><br><br><br>2. 如果执行的是 MSDOS 外部程序,如何能让它的窗口不显示出来呢? <br>[ 接上例 ]:<br>TStartupInfo 这个结构中有一个 sShowWindow 栏位, 将之设为 SW_HIDE即可,<br>同时, dwFlags 标志中至少需含有 STARTF_USESHOWWINDOW, 否则CreateProcess<br>时, sShowWindow 栏位的设定会无效, 以下是修改过的程式:<br><br>var<br> sCommandLine: string;<br> bCreateProcess: boolean;<br> lpStartupInfo: TStartupInfo;<br> lpProcessInformation: TProcessInformation;<br>begin<br> // sCommandLine 的内容请视您的情况修改<br> sCommandLine :='Xcopy d:/temp/temp1/*.* d:/temp/temp2 /v/y';<br> lpStartupInfo.dwFlags := STARTF_USESHOWWINDOW;<br> lpStartupInfo.wShowWindow := SW_HIDE;<br> bCreateProcess := CreateProcess(nil, PChar(sCommandLine),nil,nil,True,<br> HIGH_PRIORITY_CLASS, nil, nil,lpStartupInfo, lpProcessInformation);<br> if bCreateProcess then<br> WaitForSingleObject(lpProcessInformation.hProcess, INFINITE);<br>end;<br>