A
asoftforg
Unregistered / Unconfirmed
GUEST, unregistred user!
最近在写一个nmap的gui程序,知道怎样运行,但却不知道怎样停止....<br><br>go的代码如下,但怎样编写stop的代码呢?<br><br>关键步骤是creatprocess,也能得到返回值,但一旦运行,nmap运行中,程序就会失去响应,stop也点不上了....<br>那位大侠能帮一下忙?或者是提示一下新的方法?<br><br>procedure TForm1.FlatButton1Click(Sender: TObject);<br>var<br> ChrTmp: Array[0..256] of Char;<br> BufRead: Array[0..1024 * 16] of Char;<br> NumRead: DWORD;<br> PipeSA: SECURITY_ATTRIBUTES;<br>begin<br> n:=1;<br> self.Timer1.Enabled:=true;<br> self.FlatButton1.Enabled := False;<br> self.FlatMemo1.Lines.Clear;<br> self.FlatMemo1.Lines.Add('Starting nmap................ ');<br> self.FlatMemo1.Lines.Add('Nmap is working, just wait... ');<br><br> self.PageControl1.TabIndex:=0;<br> ZeroMemory(@BufRead,1024 * 16);<br><br> PipeSA.nLength := sizeof(SECURITY_ATTRIBUTES);<br> PipeSA.bInheritHandle := True;<br> PipeSA.lpSecurityDescriptor := nil;<br><br> if False = CreatePipe(hRead,hWrite,@PipeSA,0) then<br> FlatMemo1.Lines.Add('Pipe Create Error~!');<br><br> hStdTmp := GetStdHandle(STD_OUTPUT_HANDLE);<br> SetStdHandle(STD_OUTPUT_HANDLE,hWrite);<br><br> GetStartupInfo(SI);<br> SI.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;<br> SI.hStdOutput := hWrite;<br> SI.hStdError := hWrite;<br> SI.wShowWindow := SW_HIDE;<br> StrCopy(ChrTmp,PChar('nmap'));<br> CreateProcess(nil,<br> ChrTmp,<br> nil,<br> nil,<br> True,<br> 0,<br> nil,<br> nil,<br> SI,<br> ProcessInfo);<br><br> SetStdHandle(STD_OUTPUT_HANDLE,hStdTmp);<br> CloseHandle(hWrite);<br> while ReadFile(hRead,BufRead,1024 * 16,NumRead,nil) do begin<br> Sleep(1);<br> FlatMemo1.Lines.Add(BufRead);<br> ZeroMemory(@BufRead,1024 * 16);<br> end;<br><br> CloseHandle(hRead);<br> self.FlatButton1.Enabled := True;<br> self.Timer1.Enabled:=false;<br> n:=1;<br> self.FlatProgressBar1.Position:=0;<br>end;