K
kindly
Unregistered / Unconfirmed
GUEST, unregistred user!
整理以前的代码,发现这个程序,很简单的,不过也许有人不知道,就贴了上来[]<br><br>unit MainFrm;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br>type<br> TForm1 = class(TForm)<br> OpenDialog1: TOpenDialog;<br> btnRun: TButton;<br> btnOpenfile: TButton;<br> EditFilename: TEdit;<br> Memo1: TMemo;<br> procedure btnOpenfileClick(Sender: TObject);<br> procedure btnRunClick(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.btnOpenfileClick(Sender: TObject);<br>begin<br> if opendialog1.Execute then editfilename.Text :=opendialog1.FileName;<br>end;<br><br>procedure TForm1.btnRunClick(Sender: TObject);<br>var<br> hReadPipe,hWritePipe:THandle;<br> si:STARTUPINFO;<br> lsa:SECURITY_ATTRIBUTES;<br> piROCESS_INFORMATION;<br> mDosScreen:String;<br> cchReadBufferWORD;<br> phChar;<br> fnameChar;<br> i,j:integer;<br>begin<br> fname:=allocmem(255);<br> ph:=AllocMem(5000);<br> lsa.nLength :=sizeof(SECURITY_ATTRIBUTES);<br> lsa.lpSecurityDescriptor :=nil;<br> lsa.bInheritHandle :=True;<br><br> if CreatePipe(hReadPipe,hWritePipe,@lsa,0)=false then<br> begin<br> ShowMessage('Can not create pipe!');<br> exit;<br> end;<br> fillchar(si,sizeof(STARTUPINFO),0);<br> si.cb :=sizeof(STARTUPINFO);<br> si.dwFlags :=(STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW);<br> si.wShowWindow :=SW_HIDE;<br> si.hStdOutput :=hWritePipe;<br> StrPCopy(fname,EditFilename.text);<br> if CreateProcess( nil, fname, nil, nil, true, 0, nil, nil, si, pi) = False then<br> begin<br> ShowMessage('can not create process');<br> FreeMem(ph);<br> FreeMem(fname);<br> Exit;<br> end;<br><br> while(true) do<br> begin<br> if not PeekNamedPipe(hReadPipe,ph,1,@cchReadBuffer,nil,nil) then break;<br> if cchReadBuffer<>0 then<br> begin<br> if ReadFile(hReadPipe,ph^,4096,cchReadBuffer,nil)=false then break;<br> ph[cchReadbuffer]:=chr(0);<br> Memo1.Lines.Add(ph);<br> end<br> else if(WaitForSingleObject(pi.hProcess ,0)=WAIT_OBJECT_0) then break;<br> Sleep(100);<br> end;<br><br> ph[cchReadBuffer]:=chr(0);<br> Memo1.Lines.Add(ph);<br> CloseHandle(hReadPipe);<br> CloseHandle(pi.hThread);<br> CloseHandle(pi.hProcess);<br> CloseHandle(hWritePipe);<br> FreeMem(ph);<br> FreeMem(fname);<br>end;<br><br>end.<br>在命令行里打cmd/c dir看看:)<br>