本文整理自网络,侵删。
function GetNbtstat(IPstr:string): string;varhReadPipe,hWritePipe:THandle;si:STARTUPINFO;lsa:SECURITY_ATTRIBUTES;pi:PROCESS_INFORMATION;mDosScreen:String;cchReadBuffer:DWORD;ph:PansiChar;fname:PChar;i,j:integer;getinfo:string;///////////////////////////str,TEMP,ip:string;K:Integer;match:TMatch;///////////////////////////beginfname:=allocmem(255);ph:=AllocMem(5000);lsa.nLength :=sizeof(SECURITY_ATTRIBUTES);lsa.lpSecurityDescriptor :=nil;lsa.bInheritHandle :=True;trytryif CreatePipe(hReadPipe,hWritePipe,@lsa,0)=false thenbeginShowMessage('Can not create pipe!');exit;end;fillchar(si,sizeof(STARTUPINFO),0);si.cb :=sizeof(STARTUPINFO);si.dwFlags :=(STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW);si.wShowWindow :=SW_show;si.hStdOutput :=hWritePipe;//shellexecute(handle,nil,pchar('C:\Windows\System32\cmd.exe'),pchar(' /c C:\Windows\sysnative\nbtstat.exe -A 192.168.1.123 > D:\cmdtemp.txt'),nil,sw_show);//StrPCopy(fname,'C:\Windows\System32\nbtstat.exe -A '+IPstr);StrPCopy(fname,'C:\Windows\System32\cmd.exe /c C:\Windows\sysnative\nbtstat.exe -A '+IPstr);
if CreateProcess( nil, fname, nil, nil, true, 0, nil, nil, si, pi) = False thenbeginShowMessage('can not create process');FreeMem(ph);FreeMem(fname);Exit;end;
while(true) dobegin
if not PeekNamedPipe(hReadPipe,ph,1,@cchReadBuffer,nil,nil) then break;if cchReadBuffer<>0 thenbegin
if ReadFile(hReadPipe,ph^,4096,cchReadBuffer,nil)=false then break;ph[cchReadbuffer]:=chr(0);if ph<>'' thenbegin Result :=ph;end;//getinfo:=ph;//getinfo:=StringReplace (getinfo, '接口:', '本机IP', []);//Memo1.Lines.Add(getinfo);endelse if(WaitForSingleObject(pi.hProcess ,0)=WAIT_OBJECT_0) then break;Application.ProcessMessages;Sleep(100);end;ph[cchReadBuffer]:=chr(0);if ph<>'' then Result :=ph;
CloseHandle(hReadPipe);CloseHandle(pi.hThread);CloseHandle(pi.hProcess);CloseHandle(hWritePipe);FreeMem(ph);FreeMem(fname);
exceptend;finallyend;
end;
相关阅读 >>
Delphi 判断指定字符串是否开头 startstext用法
Delphi datamodule1 fdconnection1数据库连接
Delphi windows 编程[10] - wm_lbuttondown、wm_lbuttonup 和 wm_mousemove 消息
更多相关阅读请进入《Delphi》频道 >>