L
linuxping
Unregistered / Unconfirmed
GUEST, unregistred user!
我创建一个进程来运行一个安装程序,但是创建进程出错了,下面是代码,大家帮我看看:<br><br><br>。。。。<br>function IsWinpcapInstalled:Boolean;<br>var<br> IniFile:TIniFile;<br> IsInstalled:string;<br>begin<br> IniFile:=TIniFile.Create(IncludeTrailingBackslash(ExtractFilePath(ParamStr(0)))+'prj.ini');<br> IsInstalled:=IniFile.ReadString('WinPCap','Installed','False');<br> Result:=StrToBool(IsInstalled);<br> IniFile.Free;<br>end;<br><br><br><br>var<br> SA: TSecurityAttributes;<br> SI: TStartupInfo;<br> PI: TProcessInformation;<br> WinPCapPath:string;<br> AppProcess,AppThread:THandle;<br><br> <br>{$R *.res}<br><br>begin<br> Application.Initialize;<br><br> Application.CreateForm(TForm1, Form1);<br> Application.MainForm.Visible:=False;<br><br> if not IsWinpcapInstalled then<br> begin<br> frmInstall:=TfrmInstall.Create(Application);<br> frmInstall.ShowModal;<br> if Form1.InstalledWinPCap then //安装WinPCap<br> begin<br> //创建一个进程来安装WinPCap<br> FillChar(SA,SizeOf(SA),#0);<br> SA.nLength:=SizeOf(SA);<br> SA.lpSecurityDescriptor:=nil;<br> SA.bInheritHandle:=True;<br><br> FillChar(SI,SizeOf(SI),#0);<br> with SI do<br> begin<br> cb:=SizeOf(SI);<br> lpReserved:=nil;<br> lpDesktop:=nil;<br> lpTitle:=nil;<br> <br> dwFlags:=STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK ;<br> wShowWindow:=SW_SHOW;<br> cbReserved2:=0;<br> lpReserved2:=nil;<br> //hStdInput:=GetStdHandle(STD_INPUT_HANDLE);<br> //hStdError:=StdOutFile;<br> //hStdOutput:=StdOutFile;<br> end;<br><br> WinPCapPath:=IncludeTrailingBackslash(ExtractFilePath(ParamStr(0)))+'winpcap/'+'WinPcap_4_0.exe'+#0;<br> try<br> if FileExists(WinPCapPath) then<br> Application.MessageBox('asd','caption');<br> if CreateProcess(PChar(WinPCapPath), nil, nil, nil,<br> True, DEBUG_ONLY_THIS_PROCESS or NORMAL_PRIORITY_CLASS , nil,<br> PChar(WinPCapPath), SI, PI) then<br> begin<br> WaitForSingleObject(PI.hProcess,INFINITE);<br> AppProcess:=PI.hProcess;<br> AppThread:=PI.hThread;<br><br> Form1.SetWinpcapInstalled(True); //设置安装标记,表明已经安装了WinPCap。<br> end else<br> Application.MessageBox('WinPCap安装失败。 请手动安装WinPCap。','安装WinPCap');<br> <br><br> finally<br> if AppProcess <> 0 then CloseHandle(AppProcess);<br> if AppThread <> 0 then CloseHandle(AppThread);<br> end;<br> end;<br> end;<br><br> Application.MainForm.Visible:=True;<br> Application.Run;<br>end.