哪位大虾有关于类似于这样的对话框控件或代码:打开以后,能显示局域网中所有的计算机名,选中后能返回其机器名或IP地址。(50分)

  • 主题发起人 主题发起人 oqm
  • 开始时间 开始时间
O

oqm

Unregistered / Unconfirmed
GUEST, unregistred user!
哪位大虾有关于类似于这样的对话框控件或代码:打开以后,能显示局域网中所有的计算机名,选中后能返回其机器名或IP地址。
 
关注!我也想知道!
 
自己写程序来实现吧,
关于局域网中的机器的问题论坛里很多,你查查.
 
麻烦哪位大虾能粘贴出来!!!!
 
var
sl: TStringList;
...
调用GetServerListFromLan(sl, nil, True);即可将局域网内的机器列表保存到sl中;
调用GetIPFromHost(hn: string); 即可返回机器名hn对应的IP地址。

procedure GetServerListFromLan(sl: TStrings; NetResContainer: PNetResource; bRoot: Boolean);
var
NetRes: Array[0..10] of TNetResource;
r,hEnum,EntryCount,NetResLen: DWORD;
strName: String;
begin
//在下面的递归程序中应该注意 WNetOpenEnum()与WNetCloseEnum()的次数是否相同。
//如果不同,肯定是在某一次循环中出差错了,可能会漏掉未释放的资源.
r := WNetOpenEnum(RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
NetResContainer,
hEnum);

if r <> NO_ERROR then Exit;

while True do
begin
EntryCount := 1;
NetResLen := SizeOf(NetRes);

r := WNetEnumResource(hEnum, EntryCount, @NetRes, NetResLen);

case r of
NO_ERROR:
begin
if NetRes[0].dwDisplayType = RESOURCEDISPLAYTYPE_SERVER then
begin
strName := Trim(StrPas(NetRes[0].lpRemoteName));

if strName = '' then strName := Trim(StrPas(NetRes[0].lpProvider))
else Delete(strName, 1, 2);

sl.Add(strName);
end
else GetServerListFromLan(sl, @NetRes[0], False);
end;
ERROR_NO_MORE_ITEMS:
begin
WNetCloseEnum(hEnum);
Break;
end;
else
end;
end;
end;

//下面的函数需要包含WinSock单元
function GetIPFromHost(hn: string): string;
var
sData: TWSAData;
h: PHostEnt;
begin
Result := '0.0.0.0';

if WSAStartup($101, sData) = SOCKET_ERROR then Exit;

if hn <> '' then
begin
if hn[1] in ['0'..'9'] then
begin
if inet_addr(pchar(hn)) <> INADDR_NONE then
Result := hn;
end
else
begin
h := gethostbyname(pchar(hn));
if h <> nil then
with h^ do
Result := format('%d.%d.%d.%d', [ord(h_addr^[0]), ord(h_addr^[1]),
ord(h_addr^[2]), ord(h_addr^[3])]);
end;
end;

WSACleanup;
end;
 
上面这段代码我试了,说是有个abstract method。这是怎么回事?我只试了取ServerList的这段。还是,这个"抽象方法"是怎么回事啊?
 
//Windows的对话框
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, StdCtrls, ShlObj, ActiveX;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function ShowComputerName: String;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.ShowComputerName: String;
var
BrowseInfo: TBrowseInfo;
ItemIDList: PItemIDList;
ComputerName: array[0..MAX_PATH] of Char;
Title: string;
WindowList: Pointer;
bOK: Boolean;
ShellMalloc: IMalloc;
begin
if Failed(SHGetSpecialFolderLocation(Handle, CSIDL_NETWORK, ItemIDList)) then
raise Exception.Create('ComputerNameDialogNotSupported');
try
FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);
BrowseInfo.hwndOwner := Handle;
BrowseInfo.pidlRoot := ItemIDList;
BrowseInfo.pszDisplayName := ComputerName;
Title := '选择计算机';
BrowseInfo.lpszTitle := PChar(Pointer(Title));
BrowseInfo.ulFlags := BIF_BROWSEFORCOMPUTER;
WindowList := DisableTaskWindows(0);
try
bOK := SHBrowseForFolder(BrowseInfo) <> nil;
finally
EnableTaskWindows(WindowList);
end;
if bOK then Result := ComputerName;
finally
if Succeeded(SHGetMalloc(ShellMalloc)) then
ShellMalloc.Free(ItemIDList);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(ShowComputerName);
end;

end.
 
把TStrings 改成 TStrinList就不会有什么abstract method的错误了。怪。
To 独帅: 有没办法,可以使主机控制局域网上的其它机器?用消息?^_^.
 
//有没办法,可以使主机控制局域网上的其它机器?用消息?
当然有办法,远程控制的源码很多了,随便找几个参考一下
 
我有显示局域网中所有电脑的TreeView控件。
lphjj@21cn.com
 
to 独帅:
能不能给条链接?tks
 
to chenwei62:
TridiaVNC:开放源码(Open Source)、
支持多个操作系统(Windows 95/98/2000/ME/NT/XP、Linux、IBM AIX、HP-UX、SUN Solaris)的远程控制软件
http://www.tridiavnc.com/index.html
TridiaVNC (virtual network computing) software allows a user to view and control the remote screen, keyboard, and mouse of a host machine. The user simply runs the server on the host machine (the machine the user wishes to remotely control) and then connects to it with a viewer.
 
后退
顶部