谁能帮助分析一下这个程序?(100分)

  • 主题发起人 主题发起人 dream_flyer
  • 开始时间 开始时间
D

dream_flyer

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);<br><br>&nbsp;procedure RunDosInMemo(DosApp:String;AMemo:TMemo);<br>&nbsp;const<br>&nbsp; &nbsp; ReadBuffer = 2400;<br>&nbsp;var<br>&nbsp; Security &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: TSecurityAttributes;<br>&nbsp; ReadPipe,WritePipe &nbsp;: THandle;<br>&nbsp; start &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : TStartUpInfo;<br>&nbsp; ProcessInfo &nbsp; &nbsp; &nbsp; &nbsp; : TProcessInformation;<br>&nbsp; Buffer &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Pchar;<br>&nbsp; BytesRead &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : DWord;<br>&nbsp; Apprunning &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: DWord;<br>&nbsp;begin<br>&nbsp; With Security do begin<br>&nbsp; &nbsp;nlength &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= SizeOf(TSecurityAttributes);<br>&nbsp; &nbsp;binherithandle &nbsp; &nbsp; &nbsp; := true;<br>&nbsp; &nbsp;lpsecuritydescriptor := nil;<br>&nbsp; end;<br>&nbsp; if Createpipe (ReadPipe, WritePipe,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@Security, 0) then begin<br>&nbsp; &nbsp;Buffer &nbsp;:= AllocMem(ReadBuffer + 1);<br>&nbsp; &nbsp;FillChar(Start,Sizeof(Start),#0);<br>&nbsp; &nbsp;start.cb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= SizeOf(start);<br>&nbsp; &nbsp;start.hStdOutput &nbsp;:= WritePipe;<br>&nbsp; &nbsp;start.hStdInput &nbsp; := ReadPipe;<br>&nbsp; &nbsp;start.dwFlags &nbsp; &nbsp; := STARTF_USESTDHANDLES +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; STARTF_USESHOWWINDOW;<br>&nbsp; &nbsp;start.wShowWindow := SW_HIDE;<br><br>&nbsp; &nbsp;if CreateProcess(nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PChar(DosApp),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Security,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Security,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; true,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NORMAL_PRIORITY_CLASS,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; start,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ProcessInfo)<br>&nbsp; &nbsp;then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; repeat<br>&nbsp; &nbsp; &nbsp;Apprunning := WaitForSingleObject<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (ProcessInfo.hProcess,100);<br>&nbsp; &nbsp; &nbsp;Application.ProcessMessages;<br>&nbsp; &nbsp; until (Apprunning &lt;&gt; WAIT_TIMEOUT);<br>&nbsp; &nbsp; &nbsp;Repeat<br>&nbsp; &nbsp; &nbsp; &nbsp;BytesRead := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp;ReadFile(ReadPipe,Buffer[0],<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ReadBuffer,BytesRead,nil);<br>&nbsp; &nbsp; &nbsp; &nbsp;Buffer[BytesRead]:= #0;<br>&nbsp; &nbsp; &nbsp; &nbsp;OemToAnsi(Buffer,Buffer);<br>&nbsp; &nbsp; &nbsp; &nbsp;AMemo.Text := AMemo.text + String(Buffer);<br>&nbsp; &nbsp; &nbsp;until (BytesRead &lt; ReadBuffer);<br>&nbsp; end;<br>&nbsp; FreeMem(Buffer);<br>&nbsp; CloseHandle(ProcessInfo.hProcess);<br>&nbsp; CloseHandle(ProcessInfo.hThread);<br>&nbsp; CloseHandle(ReadPipe);<br>&nbsp; CloseHandle(WritePipe);<br>&nbsp; end;<br>&nbsp;end;<br><br>&nbsp;begin {button 1 code}<br>&nbsp; &nbsp;RunDosInMemo('ping 10.43.0.1',Memo1);<br>&nbsp;end; <br><br>上述程序似乎只能回显ping、ipconfig等命令,我将命令参数换成<br>'d:/.../tpc.exe d:/...pas'产生问题不能回显
 
后退
顶部