怎样列出网络上的其他计算机??????????

ygb321 2003-05-20 02:20:39
怎样列出网络上的其他计算机??????????
...全文
13 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
lion_lh 2003-05-22
老问题了,搜一下有很多,接分
回复
hezchuan168 2003-05-22
你是要搜索本地网络计算机名称和它的IP地址是吗??有很多这样的程序啊!去源码空间看看就是了.
回复
guowzgyc 2003-05-21
{*********************************************************}
{ }
{ TEricNetResource 1.0 CopyRight ?2002 Eric.Kuo }
{ }
{ The Class can find not only NetGroup's name but }
{ also all users of the NetGroup. }
{ }
{ }
{ Please Contact Eric at this address: }
{ guowz_gyc@263.net.cn }
{*********************************************************}
unit EricNetResource;

interface

uses
Windows,Classes,SysUtils;

type
TNetResourceArray = ^TNetResource;
TEricNetResource = Class(TComponent)
private
FServers :TStrings;
procedure GetServerList;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure GetUsers(GroupName:String;UserList:TStrings);
published
property Servers: TStrings read FServers;
end;
procedure Register;
implementation

constructor TEricNetResource.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FServers:=TStringlist.Create;
GetServerList;
end;

destructor TEricNetResource.Destroy;
begin
FServers.Free;
inherited Destroy;
end;

procedure TEricNetResource.GetServerList;
Var
NetResource : TNetResource;
Buf : Pointer;
Count,BufSize,Res : DWORD;
lphEnum : THandle;
p : TNetResourceArray;
i,j : SmallInt;
NetworkTypeList : TList;
Begin
NetworkTypeList := TList.Create;
Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
RESOURCEUSAGE_CONTAINER, Nil,lphEnum);
If Res <> NO_ERROR Then exit;
Count := $FFFFFFFF;
BufSize := 8192;
GetMem(Buf, BufSize);
Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);
If ( Res = ERROR_NO_MORE_ITEMS ) or (Res <> NO_ERROR ) Then Exit;
P := TNetResourceArray(Buf);
For I := 0 To Count - 1 Do
Begin
NetworkTypeList.Add(p);
Inc(P);
End;
Res := WNetCloseEnum(lphEnum);
If Res <> NO_ERROR Then exit;
For J := 0 To NetworkTypeList.Count-1 Do
Begin
NetResource := TNetResource(NetworkTypeList.Items[J]^);
//获取某个网络类型的文件资源的句柄,NetResource为网络类型信息,lphEnum为返回名柄
Res := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
RESOURCEUSAGE_CONTAINER, @NetResource,lphEnum);
If Res <> NO_ERROR Then break;
While true Do
Begin
Count := $FFFFFFFF;
BufSize := 8192;
GetMem(Buf, BufSize);
Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);
If ( Res = ERROR_NO_MORE_ITEMS ) or (Res <> NO_ERROR) then break;
P := TNetResourceArray(Buf);
For I := 0 To Count - 1 Do
Begin
FServers.Add(StrPAS( P^.lpRemoteName ));//取得一个工作组的名称
Inc(P);
End;
End;
Res := WNetCloseEnum(lphEnum);
If Res <> NO_ERROR Then break;
End;
FreeMem(Buf);
NetworkTypeList.Destroy;
End;

Procedure TEricNetResource.GetUsers(GroupName:String;UserList:TStrings);
Var
NetResource : TNetResource;
Buf : Pointer;
Count,BufSize,Res : DWord;
Ind : Integer;
lphEnum : THandle;
Temp : TNetResourceArray;
Begin
UserList.Clear;
FillChar(NetResource, SizeOf(NetResource), 0);
NetResource.lpRemoteName := @GroupName[1];
NetResource.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;
NetResource.dwUsage := RESOURCEUSAGE_CONTAINER;
NetResource.dwScope := RESOURCETYPE_DISK;
Res := WNetOpenEnum( RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
RESOURCEUSAGE_CONTAINER, @NetResource,lphEnum);
If Res <> NO_ERROR Then Exit;
While True Do
Begin
Count := $FFFFFFFF;
BufSize := 8192;
GetMem(Buf, BufSize);
Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);
If Res = ERROR_NO_MORE_ITEMS Then break;
If (Res <> NO_ERROR) then Exit;
Temp := TNetResourceArray(Buf);
For Ind := 0 to Count - 1 do
Begin
//获取工作组的计算机名称,+2表示删除"\\",如\\guoyunchang=>guoyunchang
UserList.Add(Temp^.lpRemoteName + 2);
Inc(Temp);
End;
End;
Res := WNetCloseEnum(lphEnum);
If Res <> NO_ERROR Then exit;
FreeMem(Buf);
End;

procedure Register;
begin
RegisterComponents('Eric',[TEricNetResource]);
end;

end.
回复
相关推荐
发帖
网络通信/分布式开发
创建于2007-08-02

1573

社区成员

Delphi 网络通信/分布式开发
申请成为版主
帖子事件
创建了帖子
2003-05-20 02:20
社区公告
暂无公告