delphi 调用DOS Nbtstat 并获得结果


本文整理自网络,侵删。

 
function GetNbtstat(IPstr:string): string;
var
hReadPipe,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;
///////////////////////////
begin
fname:=allocmem(255);
ph:=AllocMem(5000);
lsa.nLength :=sizeof(SECURITY_ATTRIBUTES);
lsa.lpSecurityDescriptor :=nil;
lsa.bInheritHandle :=True;
try
try
if CreatePipe(hReadPipe,hWritePipe,@lsa,0)=false then
begin
ShowMessage('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 then
begin
ShowMessage('can not create process');
FreeMem(ph);
FreeMem(fname);
Exit;
end;

while(true) do
begin

if not PeekNamedPipe(hReadPipe,ph,1,@cchReadBuffer,nil,nil) then break;
if cchReadBuffer<>0 then
begin

if ReadFile(hReadPipe,ph^,4096,cchReadBuffer,nil)=false then break;
ph[cchReadbuffer]:=chr(0);
if ph<>'' then
begin
 Result :=ph;
end;
//getinfo:=ph;
//getinfo:=StringReplace (getinfo, '接口:', '本机IP', []);
//Memo1.Lines.Add(getinfo);
end
else 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);

except
end;
finally
end;

end;

相关阅读 >>

Delphi 大小写字符串转换

tidtcpserver控件中文指南

Delphi中move函数的正确理解

Delphi 字符串显示后5位

Delphi jpg图像加文字水印

Delphi禁止在android上重复按下按钮

Delphi 保存图片到数据库

Delphi三层开发小技巧:tclientdataset的delta妙用

Delphi nativeexcel获取excel所有列

删除Delphi组件tstringlist中的重复项目

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...