to hnzgf:<br>这两天我受 一个VC例子的启发(具体实现同你的方法差不多)尝试开一个线程来做,<br>(以前不是用一个进程来做的嘛),具体方法如下:<br> sleep(10000),目的主要是为了调试,又是执行到箭头处,死机,连线程也不再执行,<br>如果再单步执行 WaitforSingleObject(MainProcessInfo, INFINITE)句,结果由于此句的<br>执行, 产生对线程的等待,导致 主程序也死了。 <br> 为什么????唉!实在不行的话,我就只能用 Vc++试试看了(不过不大熟)<br>主程序:(摘要)<br>var<br> Form1: TForm1;<br> MainProcessInfo : Thandle ;<br> Mainthread:thandle;<br>begin<br> Path:=ExtractFilePath(Application.Exename);<br> MyThread.Create(path+'win32/install/orainst.exe /silent /prd win95.prd /rspsrc client_ok.rsp',SW_SHOWNORMAL);<br> sleep(10000);<br>------> WaitforSingleObject(MainProcessInfo, INFINITE);//后面的 时间参数 决定进程无限期等待<br> CloseHandle(MainProcessInfo); { to prevent memory leaks }<br> CloseHandle(Mainthread);<br>end<br>线程如下:<br>unit ViceHanshu;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls, FileCtrl;<br><br>type<br> MyThread = class(TThread)<br> private<br> { Private declarations }<br> FileName: string;<br> Visibility: integer;<br> protected<br> procedure Execute; override;<br> function WinExecAndWait32_v1(FileName: string; Visibility: integer): Cardinal;<br> public<br>constructor Create(ViceFileName: string; ViceVisibility: integer);<br> end;<br>implementation<br> uses main;<br>{ MyThread }<br>function MyThread.WinExecAndWait32_v1(FileName: string; Visibility: integer): Cardinal;<br>var<br> zAppName: array[0..512] of char;<br> zCurDir: array[0..255] of char;<br> WorkDir: string;<br> StartupInfo: TStartupInfo;//这是创建一个新进程的 显示时必要的结构信息<br> ProcessInfo: TProcessInformation;<br>begin<br> StrPCopy(zAppName, FileName); //文件名格式的转换§该函数将典型的pascal字符串变为 以0结尾的字符串指针(windows通用)<br> FillChar(StartupInfo, Sizeof(StartupInfo), #0);//将这个结构 全部用空格填充<br> StartupInfo.cb := Sizeof(StartupInfo);<br> StartupInfo.dwFlags := STARTF_USESHOWWINDOW;//窗口布局管理,为此值,下面一属性才能起作用<br> StartupInfo.wShowWindow := Visibility; //主要是确定窗口显示的风格,与winexec是一样的<br> if not CreateProcess(nil, //这里如果部位空,则只能为一个 可执行程序<br> zAppName, { pointer to command line string }<br> nil, //进程优先级别<br> nil, //线程优先级别<br> true, { handle inheritance flag }<br> CREATE_NEW_CONSOLE or { creation flags }<br> NORMAL_PRIORITY_CLASS,<br> nil, { pointer to new environment block }<br> nil, { pointer to current directory name, PChar}<br> StartupInfo, { pointer to STARTUPINFO }<br> ProcessInfo) //声明一个结构来存储 进程的消息。<br> then Result := INFINITE else<br> begin<br> MainProcessInfo:= ProcessInfo.hProcess;<br> end;<br>end;<br>constructor mythread.Create(ViceFileName: string; ViceVisibility: integer);<br>begin<br> filename:= ViceFileName;<br> visibility:= ViceVisibility;<br> //FreeOnTerminate := True;<br> inherited Create(False); //表示一创建就执行<br>end;<br>procedure MyThread.Execute;<br>begin<br> { Place thread code here }<br> WinExecAndWait32_v1(FileName, Visibility);<br>end;<br>end.