说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

在程序中动态取得Win95/98网络邻居中工作组及计算机名-Delphi资料

HTML文档下载 WORD文档下载 PDF文档下载
在程序中动态取得Win95/98网络邻居中工作组及计算机名-Delphi资料

可参考下面代码,或许有所帮助:

procedure GetDomainList(TV:TTreeView);

var

a : Integer;

ErrCode : Integer;

NetRes : Array[0..1023] of TNetResource;

EnumHandle : THandle;

EnumEntries : DWord;

BufferSize : DWord;

s : string;

itm : TTreeNode;

begin

{ Start here }

try

With NetRes[0] do begin

dwScope :=RESOURCE_GLOBALNET;

dwType :=RESOURCETYPE_ANY;

dwDisplayType :=RESOURCEDISPLAYTYPE_DOMAIN;

dwUsage :=RESOURCEUSAGE_CONTAINER;

lpLocalName :=NIL;

lpRemoteName :=NIL;

lpComment :=NIL;

lpProvider :=NIL;

end;

{ get net root }

ErrCode:=WNetOpenEnum(RESOURCE_GLOBALNET

RESOURCETYPE_ANY

RESOURCEUSAGE_CONTAINER

@NetRes[0]

EnumHandle);

If ErrCode=NO_ERROR then

begin

EnumEntries:=1;

BufferSize:=SizeOf(NetRes);

ErrCode:=WNetEnumResource(EnumHandle

EnumEntries

@NetRes[0]

BufferSize);

WNetCloseEnum(EnumHandle);

ErrCode:=WNetOpenEnum(RESOURCE_GLOBALNET

RESOURCETYPE_ANY

RESOURCEUSAGE_CONTAINER

@NetRes[0]

EnumHandle);

EnumEntries:=1024;

BufferSize:=SizeOf(NetRes);

ErrCode:=WNetEnumResource(EnumHandle

EnumEntries

@NetRes[0]

BufferSize);

IF ErrCode=No_Error then with TV do try

a:=0;

Items.BeginUpDate;

Items.Clear;

Itm:=Items.Add(TV.Selected

string(NetRes[0].lpProvider));

Itm.ImageIndex:=0;

Itm.SelectedIndex:=0;

{ get domains }

下面的一个单元定义了一个组件. TNetworkBrowser

可以枚举hierachical树上所有的网络资源. 实际上浏览是要花费很长时间的

这您可以通过在WINDOWS资源管理器中打开"整个网络" 来比较一下. 如果你设置SCOPE属性 为nsContext

你就可以看到和网络邻居中一样的机器列表.

unit NetBrwsr;

interface

uses

Windows

Messages

SysUtils

Classes

Graphics

Controls

Forms

Dialogs;

type

TNetScope = (nsConnected

nsGlobal

nsRemembered

nsContext);

TNetResourceType = (nrAny

nrDisk

nrPrint);

TNetDisplay = (ndDomain

ndGeneric

ndServer

ndShare

ndFile

ndGroup

ndNetwork

ndRoot

ndShareAdmin

ndDirectory

ndTree

ndNDSContainer);

TNetUsage = set of (nuConnectable

nuContainer);

TNetworkItems = class;

TNetworkItem = class

private

FScope: TNetScope;

FResourceType: TNetResourceType;

FDisplay: TNetDisplay;

FUsage: TNetUsage;

FLocalName: string;

FRemoteName: string;

FComment: string;

FProvider: string;

FSubItems: TNetworkItems;

public

constructor Create;

destructor Destroy; override;

property Scope: TNetScope read FScope;

property ResourceType: TNetResourceType read FResourceType;

property Display: TNetDisplay read FDisplay;

property Usage: TNetUsage read FUsage;

property LocalName: string read FLocalName;

property RemoteName: string read FRemoteName;

property Comment: string read FComment;

property Provider: string read FProvider;

property SubItems: TNetworkItems read FSubItems;

end;

TNetworkItems = class

private

FList: TList;

procedure SetItem(Index: Integer; Value: TNetworkItem);

function GetItem(Index: Integer): TNetworkItem;

function GetCount: Integer;

public

constructor Create;

destructor Destroy; override;

procedure Clear;

procedure Add(Item: TNetworkItem);

procedure Delete(Index: Integer);

property Items[Index: Integer]: TNetworkItem read GetItem write

SetItem; default;

property Count: Integer read GetCount;

end;

TNetworkBrowser = class(TComponent)

private

FItems: TNetworkItems;

FScope: TNetScope;

FResourceType: TNetResourceType;

FUsage: TNetUsage;

FActive: Boolean;

procedure Refresh;

procedure SetActive(Value: Boolean);

procedure SetScope(Value: TNetScope);

procedure SetResourceType(Value: TNetResourceType);

procedure SetUsage(Value: TNetUsage);

procedure EnumerateNet(NetItems: TNetworkItems; lpnr: PNetResource);

protected

public

constructor Create(AOwner: TComponent); override;

destructor Destroy; override;

procedure Open;

procedure Close;

property Items: TNetworkItems read FItems;

published

property Scope: TNetScope read FScope write SetScope default nsGlobal;

property ResourceType: TNetResourceType read FResourceType

write SetResourceType default nrAny;

property Usage: TNetUsage read FUsage write SetUsage default [];

property Active: Boolean read FActive write SetActive default False;

end;

implementation

type

PNetResourceArray = ^TNetResourceArray;

TNetResourceArray = array[0..0] of TNetResource;

{ TNetworkItem }

constructor TNetworkItem.Create;

begin

inherited;

FSubItems := TNetworkItems.Create;

end;

destructor TNetworkItem.Destroy;

begin

if FSubItems <> nil then

FSubItems.Free;

inherited;

end;

{ TNetworkItems }

constructor TNetworkItems.Create;

begin

inherited;

FList := TList.Create;

end;

destructor TNetworkItems.Destroy;

begin

Clear;

if FList <> nil then

FList.Free;

inherited;

end;

procedure TNetworkItems.SetItem(Index: Integer; Value: TNetworkItem);

begin

if (FList.Items[Index] <> nil) and (FList.Items[Index] <> Value) then

TNetworkItem(FList.Items[Index]).Free;

FList.Items[Index] := Value;

end;

function TNetworkItems.GetItem(Index: Integer): TNetworkItem;

begin

Result := TNetworkItem(FList.Items[Index]);

end;

procedure TNetworkItems.Clear;

begin

while Count > 0 do

Delete(0);

end;

procedure TNetworkItems.Add(Item: TNetworkItem);

begin

FList.Add(Item);

end;

procedure TNetworkItems.Delete(Index: Integer);

begin

if FList.Items[Index] <> nil then

TNetworkItem(FList.Items[Index]).Free;

FList.Delete(Index);

end;

function TNetworkItems.GetCount: Integer;

begin

if FList <> nil then

Result := FList.Count

else

Result := 0;

end;

{ TNetworkBrowser }

constructor TNetworkBrowser.Create(AOwner: TComponent);

begin

inherited Create(AOwner);

FItems := TNetworkItems.Create;

FScope := nsGlobal;

FResourceType := nrAny;

FUsage := [];

end;

destructor TNetworkBrowser.Destroy;

begin

if FItems <> nil then

FItems.Free;

inherited;

end;

procedure TNetworkBrowser.EnumerateNet(NetItems: TNetworkItems; lpnr:

PNetResource);

var

dwResult

dwResultEnum: Integer;

hEnum: THandle;

cbBuffer

cEntries

i: Integer;

nrArray: PNetResourceArray;

NewItem: TNetworkItem;

dwScope

dwType

dwUsage: Integer;

begin

cbBuffer := 16384;

cEntries := $FFFFFFFF;

case FScope of

nsConnected: dwScope := RESOURCE_CONNECTED;

nsGlobal: dwScope := RESOURCE_GLOBALNET;

nsRemembered: dwScope := RESOURCE_REMEMBERED;

nsContext: dwScope := RESOURCE_CONTEXT;

else

dwScope := RESOURCE_GLOBALNET;

end;

case FResourceType of

nrAny: dwType := RESOURCETYPE_ANY;

nrDisk: dwType := RESOURCETYPE_DISK;

nrPrint: dwType := RESOURCETYPE_PRINT;

else

dwType := RESOURCETYPE_ANY;

end;

dwUsage := 0;

if nuConnectable in FUsage then

dwUsage := dwUsage or RESOURCEUSAGE_CONNECTABLE;

if nuContainer in FUsage then

dwUsage := dwUsage or RESOURCEUSAGE_CONTAINER;

dwResult := WNetOpenEnum(dwScope

dwType

dwUsage

lpnr

hEnum);

if dwResult <> NO_ERROR then Exit;

GetMem(nrArray

cbBuffer);

repeat

dwResultEnum := WNetEnumResource(hEnum

cEntries

nrArray

cbBuffer);

if dwResultEnum = NO_ERROR then

for i := 0 to cEntries-1 do

begin

NewItem := TNetworkItem.Create;

case nrArray[i].dwScope of

RESOURCE_CONNECTED: NewItem.FScope := nsConnected;

RESOURCE_GLOBALNET: NewItem.FScope := nsGlobal;

RESOURCE_REMEMBERED: NewItem.FScope := nsRemembered;

RESOURCE_CONTEXT: NewItem.FScope := nsContext;

else

NewItem.FScope := nsGlobal;

end;

case nrArray[i].dwType of

RESOURCETYPE_ANY: NewItem.FResourceType := nrAny;

RESOURCETYPE_DISK: NewItem.FResourceType := nrDisk;

RESOURCETYPE_PRINT: NewItem.FResourceType := nrPrint;

else

NewItem.FResourceType := nrAny;

end;

case nrArray[i].dwDisplayType of

RESOURCEDISPLAYTYPE_GENERIC: NewItem.FDisplay := ndGeneric;

RESOURCEDISPLAYTYPE_DOMAIN: NewItem.FDisplay := ndDomain;

RESOURCEDISPLAYTYPE_SERVER: NewItem.FDisplay := ndServer;

RESOURCEDISPLAYTYPE_SHARE: NewItem.FDisplay := ndShare;

RESOURCEDISPLAYTYPE_FILE: NewItem.FDisplay := ndFile;

RESOURCEDISPLAYTYPE_GROUP: NewItem.FDisplay := ndGroup;

RESOURCEDISPLAYTYPE_NETWORK: NewItem.FDisplay := ndNetwork;

RESOURCEDISPLAYTYPE_ROOT: NewItem.FDisplay := ndRoot;

RESOURCEDISPLAYTYPE_SHAREADMIN: NewItem.FDisplay :=

ndShareAdmin;

RESOURCEDISPLAYTYPE_DIRECTORY: NewItem.FDisplay :=

ndDirectory;

RESOURCEDISPLAYTYPE_TREE: NewItem.FDisplay := ndTree;

RESOURCEDISPLAYTYPE_NDSCONTAINER: NewItem.FDisplay :=

ndNDSContainer;

else

NewItem.FDisplay := ndGeneric;

end;

NewItem.FUsage := [];

if nrArray[i].dwUsage and RESOURCEUSAGE_CONNECTABLE <> 0 then

Include(NewItem.FUsage

nuConnectable);

if nrArray[i].dwUsage and RESOURCEUSAGE_CONTAINER <> 0 then

Include(NewItem.FUsage

nuContainer);

NewItem.FLocalName := StrPas(nrArray[i].lpLocalName);

NewItem.FRemoteName := StrPas(nrArray[i].lpRemoteName);

NewItem.FComment := StrPas(nrArray[i].lpComment);

NewItem.FProvider := StrPas(nrArray[i].lpProvider);

NetItems.Add(NewItem);

// if container

call recursively

if (nuContainer in NewItem.FUsage) and (FScope <> nsContext) then

EnumerateNet(NewItem.FSubItems

@nrArray[i])

end;

until dwResultEnum = ERROR_NO_MORE_ITEMS;

FreeMem(nrArray);

WNetCloseEnum(hEnum);

end;

procedure TNetworkBrowser.Refresh;

begin

FItems.Clear;

if FActive then

EnumerateNet(FItems

nil);

end;

procedure TNetworkBrowser.SetActive(Value: Boolean);

begin

if Value <> FActive then

begin

FActive := Value;

Refresh;

end;

end;

procedure TNetworkBrowser.SetScope(Value: TNetScope);

begin

if Value <> FScope then

begin

FScope := Value;

Refresh;

end;

end;

procedure TNetworkBrowser.SetResourceType(Value: TNetResourceType);

begin

if Value <> FResourceType then

begin

FResourceType := Value;

Refresh;

end;

end;

procedure TNetworkBrowser.SetUsage(Value: TNetUsage);

begin

if Value <> FUsage then

begin

FUsage := Value;

Refresh;

end;

end;

procedure TNetworkBrowser.Open;

begin

Active := True;

end;

procedure TNetworkBrowser.Close;

begin

Active := False;

end;

开发者下一个待开发市场:印度 一周消息树:80%开发者背井离乡,70%经常加班 移动周报:最受欢迎的跨平台开发工具推荐 研发周报:Mt.Gox破产,都是错误编程惹的祸 数据挖掘+人工智能,教育定制化下的学霸量产 通过700合作伙伴的进一步细分,Google变得越来越像微软 一周热点:高薪必备:Hadoop求职者的6大攻略 谷歌Android主管:两周内为开发者推出可穿戴设备SDK 【OSTC讲师专访】魏子钧: “中国式开源”没有“然后” 揭秘CarPlay欲将颠覆汽车产业的真相 联想王岳源:利用Web App推动互联网转型 IT经理人:提高团队工作效率的11个方法 30美元一小时,数据科学家的收入是否太低? 选择Go语言的12个理由 动鱼数码携三款大作参战Unity游戏及应用大赛 从Google、Apple、Dropbox、Twitter和Square学到的管理哲学 软件开发就像炒股,关键看你怎么选股票! iOS 7.1正式版:新增CarPlay连接功能、完美支持iPhone 4 【OSTC讲师专访】马全一:Docker,Hadoop的竞争者来了! 福布斯:全球那些富可敌国的科技大佬们 抢工作、争资源,如此聪明的AI你拿什么阻止? iUI:移动Web应用开发必备的开源框架 支持iOS 7.1!苹果发布Xcode 5.1更新 视频云将成为2014年乐视新的发力点 3月12日:万维网迎来理念诞生25周年 《近匠》云适配CEO陈本峰:跨屏移动,曲线一样救国 Intel陈荣坤:赢取移动市场的几个先决条件 而立之年,开发者在害怕什么? 首席工程师揭秘:LinkedIn大数据后台是如何运作的 年交易额1800亿美元,揭秘PayPal成功背后的三大热门技术 微软妥协Android?向该平台推开源Office 365 SDK 来这儿去高分!!!! 各位前辈有谁用MS SQL SERVER 2000的请进! 谁有"我家我设计"(圆方的系统)的注册码? 残啊?都要计算机专业毕业的。。。。。 怎样求得两时间相差10天? 各位高手们 关于ATL COM 在98和2000下的区别 关于CEvent 如何判断commondialog.showsave ,用户是按了确定,还是取消按钮? 我最近编写一个DLL,用来实现ftp功能,使用了delphi中的nmftp控件,结束调用后总出现莫名其妙的内存错误。请高手指教! 请问哪里有win2000 server的软件下呀?迫切需要,恳请各位能帮忙!谢谢! 面试时问主考官什么样的问题算有水平? 我枚举一个外部程序的子窗体,可是却只看到了TDXDraw,我怎么样才能得到TDXDraw中更多的信息呢? 帶一個checkbox的list應該怎麼做? 扫描程序如何循环处理一段IP地址? 数据库中图片如何调用? 如下错误是什么意思,如果解决 一个关于SQL的问题 残啊?都要计算机专业毕业的。。。。。 Miscrosoft Scrioting Library是何东东?Scrrun.dll上那去弄? 如何让softice支持usb鼠标,键盘 多线程程序中使用采用单线程编译参数编译的DLL,会有什么后果? 很多on error goto ... 很简单,有NT4.0或XP的朋友一看就知道。在线等待 手工配置Grub:希望能对大家有所帮助 新显卡驱动For Linux Where download? ADO问题?????????????/ 请问c++的handle class是什么东东呀 怎么textBox控件不可以使用 \n,\r等语句?????? CEdit疑问 急切在线等:打包时出现的问题! 今天我生日,放分!!! 网络财务系统管理信息系统源代码销售 pb8的序列号问题!............................在线等待!!! 在javscript里面怎么判断一个变量(var定义的)是数字? 在线!!!哪位知道好的关于DSP的论坛? 请教高手,如何编程实现一台计算机通过拨号(modem)连接到对方计算机,并实现文件传输? ■■■有没有右键菜单也像VS.NET风格的???■■■ 有没有现成控件,实现EXCELL式的编辑功能 关于BCB中开发DirectDraw的问题 诚聘高手开发电子辞典? 请问一下了dbeng7 -Q的有关事项了? 高手请拉兄弟一把:TField 有一个OnValidate事件,可用它来校验,能否利用它来替换? 怎样把DataSet里面的数据写入一个Excel和Access文件里面? DX全屏模式下如何显示MFC控件? 关于保存对话框的问题,请教高手,谢 (简单问题送分)如何得到select语句得到的数局条数??? 谁能答出来?给分500!!! 很奇怪的问题了 c/s模式,后台是sql server 关于保存对话框的问题,请教高手,谢
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘