用什么语句能得到网上邻居所有机器名?(50分)

  • 主题发起人 主题发起人 lwaif
  • 开始时间 开始时间
L

lwaif

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样能得到网上邻居所有电脑的名字列表?
 
老问题了,检索一下就可以找到答案了
 
我提供你代码:<br>var &nbsp; &nbsp; Computer: Array[1..500] of String[25];<br>&nbsp; &nbsp; &nbsp; &nbsp; ComputerCount: Integer;<br>procedure FindAllComputers(Workgroup : String);<br>Var<br>EnumHandle: THandle;<br>WorkgroupRS: TNetResource;<br>Buf: Array[1..500] of TNetResource;<br>BufSize: DWORD;<br>Entries: DWORD;<br>Result: integer;<br><br>begin<br>ComputerCount := 0;<br><br>Workgroup := Workgroup + #0;<br><br>FillChar(WorkgroupRS, SizeOf(WorkgroupRS) , 0);<br>With WorkgroupRS do begin<br>dwScope := 2;<br>dwType := 3;<br>dwDisplayType := 1;<br>dwUsage := 2;<br>lpRemoteName := @Workgroup[1];<br>end;<br><br>WNetOpenEnum( RESOURCE_GLOBALNET,RESOURCETYPE_ANY,0,@WorkgroupRS,EnumHandle );<br>Repeat<br>Entries := 1;<br>BufSize := SizeOf(Buf);<br>Result:=WNetEnumResource(EnumHandle,Entries,@Buf,BufSize );<br>If (Result = NO_ERROR) and (Entries = 1) then begin<br>Inc( ComputerCount );<br>Computer[ ComputerCount ] := StrPas(Buf[1].lpRemoteName);<br>end;<br>Until (Entries &lt;&gt; 1) or (Result &lt;&gt; NO_ERROR);<br><br>WNetCloseEnum( EnumHandle );<br>end;
 
如果你问如何能得到网络邻居的列表,那是一个非常复杂的任务 <br>您将不得不和非常不友好的OLE对象打交道<br>下面两个过程可能会对你有用<br>procedure GetDomainList(TV:TTreeView);<br>var<br>&nbsp; a &nbsp; &nbsp; &nbsp; : Integer;<br>&nbsp; ErrCode : Integer;<br>&nbsp; NetRes &nbsp;: Array[0..1023] of TNetResource;<br>&nbsp; EnumHandle : THandle;<br>&nbsp; EnumEntries : DWord;<br><br>&nbsp; BufferSize &nbsp;: DWord;<br>&nbsp; s &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : string;<br>&nbsp; itm &nbsp; &nbsp; &nbsp; &nbsp; : TTreeNode;<br>begin<br>&nbsp; { Start here }<br>&nbsp; try<br>&nbsp; &nbsp; With NetRes[0] do begin<br>&nbsp; &nbsp; &nbsp; dwScope &nbsp; &nbsp; &nbsp; :=RESOURCE_GLOBALNET;<br>&nbsp; &nbsp; &nbsp; dwType &nbsp; &nbsp; &nbsp; &nbsp;:=RESOURCETYPE_ANY;<br>&nbsp; &nbsp; &nbsp; dwDisplayType :=RESOURCEDISPLAYTYPE_DOMAIN;<br>&nbsp; &nbsp; &nbsp; dwUsage &nbsp; &nbsp; &nbsp; :=RESOURCEUSAGE_CONTAINER;<br>&nbsp; &nbsp; &nbsp; lpLocalName &nbsp; :=NIL;<br>&nbsp; &nbsp; &nbsp; lpRemoteName &nbsp;:=NIL;<br>&nbsp; &nbsp; &nbsp; lpComment &nbsp; &nbsp; :=NIL;<br>&nbsp; &nbsp; &nbsp; lpProvider &nbsp; &nbsp;:=NIL;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; { get net root }<br>&nbsp; &nbsp; ErrCode:=WNetOpenEnum(<br>&nbsp; &nbsp; &nbsp; RESOURCE_GLOBALNET,<br>&nbsp; &nbsp; &nbsp; RESOURCETYPE_ANY,<br>&nbsp; &nbsp; &nbsp; RESOURCEUSAGE_CONTAINER,<br>&nbsp; &nbsp; &nbsp; @NetRes[0],<br><br>&nbsp; &nbsp; &nbsp; EnumHandle<br>&nbsp; &nbsp; );<br>&nbsp; &nbsp; If ErrCode=NO_ERROR then begin<br>&nbsp; &nbsp; &nbsp; EnumEntries:=1;<br>&nbsp; &nbsp; &nbsp; BufferSize:=SizeOf(NetRes);<br>&nbsp; &nbsp; &nbsp; ErrCode:=WNetEnumResource(<br>&nbsp; &nbsp; &nbsp; &nbsp; EnumHandle,<br>&nbsp; &nbsp; &nbsp; &nbsp; EnumEntries,<br>&nbsp; &nbsp; &nbsp; &nbsp; @NetRes[0],<br>&nbsp; &nbsp; &nbsp; &nbsp; BufferSize<br>&nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; WNetCloseEnum(EnumHandle);<br>&nbsp; &nbsp; &nbsp; ErrCode:=WNetOpenEnum(<br>&nbsp; &nbsp; &nbsp; &nbsp; RESOURCE_GLOBALNET,<br>&nbsp; &nbsp; &nbsp; &nbsp; RESOURCETYPE_ANY,<br>&nbsp; &nbsp; &nbsp; &nbsp; RESOURCEUSAGE_CONTAINER,<br>&nbsp; &nbsp; &nbsp; &nbsp; @NetRes[0],<br>&nbsp; &nbsp; &nbsp; &nbsp; EnumHandle<br>&nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; EnumEntries:=1024;<br>&nbsp; &nbsp; &nbsp; BufferSize:=SizeOf(NetRes);<br>&nbsp; &nbsp; &nbsp; ErrCode:=WNetEnumResource(<br>&nbsp; &nbsp; &nbsp; &nbsp; EnumHandle,<br>&nbsp; &nbsp; &nbsp; &nbsp; EnumEntries,<br>&nbsp; &nbsp; &nbsp; &nbsp; @NetRes[0],<br>&nbsp; &nbsp; &nbsp; &nbsp; BufferSize<br>&nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; IF ErrCode=No_Error then with TV do try<br>&nbsp; &nbsp; &nbsp; &nbsp; a:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; Items.BeginUpDate;<br>&nbsp; &nbsp; &nbsp; &nbsp; Items.Clear;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; Itm:=Items.Add(TV.Selected,string(NetRes[0].lpProvider));<br>&nbsp; &nbsp; &nbsp; &nbsp; Itm.ImageIndex:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; Itm.SelectedIndex:=0;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; { get domains }<br>&nbsp; &nbsp; &nbsp; &nbsp; While a How can I get the contents of the Neighborhood?<br><br>The following unit defines a component, TNetworkBrowser, which can be used<br>to enumerate all resources on the network in a hierarchical tree. The<br>actual browsing takes a long time (try opening "Entire Network" in Windows<br>Explorer). If you set the Scope property to nsContext, you'll see the list<br><br>of machines from the "Network Neighborhood" window.<br>下面的一个单元定义了一个组件. TNetworkBrowser, 可以枚举hierachical树上所有<br>的网络资源. 实际上浏览是要花费很长时间的,这您可以通过在WINDOWS资源管理器<br>中打开"整个网络" 来比较一下. 如果你设置SCOPE属性 为nsContext , 你就可以看到<br>和网络邻居中一样的机器列表<br><br>Yorai Aminov<br>El-On Software Systems<br><br>unit NetBrwsr;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;<br><br>type<br>&nbsp; TNetScope = (nsConnected, nsGlobal, nsRemembered, nsContext);<br><br>&nbsp; TNetResourceType = (nrAny, nrDisk, nrPrint);<br>&nbsp; TNetDisplay = (ndDomain, ndGeneric, ndServer, ndShare, ndFile, ndGroup,<br>&nbsp; &nbsp; ndNetwork, ndRoot, ndShareAdmin, ndDirectory, ndTree, ndNDSContainer);<br>&nbsp; TNetUsage = set of (nuConnectable, nuContainer);<br><br>&nbsp; TNetworkItems = class;<br><br>&nbsp; TNetworkItem = class<br>&nbsp; private<br>&nbsp; &nbsp; FScope: TNetScope;<br>&nbsp; &nbsp; FResourceType: TNetResourceType;<br>&nbsp; &nbsp; FDisplay: TNetDisplay;<br>&nbsp; &nbsp; FUsage: TNetUsage;<br>&nbsp; &nbsp; FLocalName: string;<br>&nbsp; &nbsp; FRemoteName: string;<br>&nbsp; &nbsp; FComment: string;<br>&nbsp; &nbsp; FProvider: string;<br>&nbsp; &nbsp; FSubItems: TNetworkItems;<br>&nbsp; public<br>&nbsp; &nbsp; constructor Create;<br>&nbsp; &nbsp; destructor Destroy; override;<br>&nbsp; &nbsp; property Scope: TNetScope read FScope;<br><br>&nbsp; &nbsp; property ResourceType: TNetResourceType read FResourceType;<br>&nbsp; &nbsp; property Display: TNetDisplay read FDisplay;<br>&nbsp; &nbsp; property Usage: TNetUsage read FUsage;<br>&nbsp; &nbsp; property LocalName: string read FLocalName;<br>&nbsp; &nbsp; property RemoteName: string read FRemoteName;<br>&nbsp; &nbsp; property Comment: string read FComment;<br>&nbsp; &nbsp; property Provider: string read FProvider;<br>&nbsp; &nbsp; property SubItems: TNetworkItems read FSubItems;<br>&nbsp; end;<br><br>&nbsp; TNetworkItems = class<br>&nbsp; private<br>&nbsp; &nbsp; FList: TList;<br>&nbsp; &nbsp; procedure SetItem(Index: Integer; Value: TNetworkItem);<br>&nbsp; &nbsp; function GetItem(Index: Integer): TNetworkItem;<br><br>&nbsp; &nbsp; function GetCount: Integer;<br>&nbsp; public<br>&nbsp; &nbsp; constructor Create;<br>&nbsp; &nbsp; destructor Destroy; override;<br>&nbsp; &nbsp; procedure Clear;<br>&nbsp; &nbsp; procedure Add(Item: TNetworkItem);<br>&nbsp; &nbsp; procedure Delete(Index: Integer);<br>&nbsp; &nbsp; property Items[Index: Integer]: TNetworkItem read GetItem write<br>SetItem; default;<br>&nbsp; &nbsp; property Count: Integer read GetCount;<br>&nbsp; end;<br><br>&nbsp; TNetworkBrowser = class(TComponent)<br>&nbsp; private<br>&nbsp; &nbsp; FItems: TNetworkItems;<br>&nbsp; &nbsp; FScope: TNetScope;<br>&nbsp; &nbsp; FResourceType: TNetResourceType;<br>&nbsp; &nbsp; FUsage: TNetUsage;<br>&nbsp; &nbsp; FActive: Boolean;<br>&nbsp; &nbsp; procedure Refresh;<br>&nbsp; &nbsp; procedure SetActive(Value: Boolean);<br>&nbsp; &nbsp; procedure SetScope(Value: TNetScope);<br><br>&nbsp; &nbsp; procedure SetResourceType(Value: TNetResourceType);<br>&nbsp; &nbsp; procedure SetUsage(Value: TNetUsage);<br>&nbsp; &nbsp; procedure EnumerateNet(NetItems: TNetworkItems; lpnr: PNetResource);<br>&nbsp; protected<br>&nbsp; public<br>&nbsp; &nbsp; constructor Create(AOwner: TComponent); override;<br>&nbsp; &nbsp; destructor Destroy; override;<br>&nbsp; &nbsp; procedure Open;<br>&nbsp; &nbsp; procedure Close;<br>&nbsp; &nbsp; property Items: TNetworkItems read FItems;<br>&nbsp; published<br>&nbsp; &nbsp; property Scope: TNetScope read FScope write SetScope default nsGlobal;<br>&nbsp; &nbsp; property ResourceType: TNetResourceType read FResourceType<br>&nbsp; &nbsp; &nbsp; write SetResourceType default nrAny;<br>&nbsp; &nbsp; property Usage: TNetUsage read FUsage write SetUsage default [];<br><br>&nbsp; &nbsp; property Active: Boolean read FActive write SetActive default False;<br>&nbsp; end;<br><br>implementation<br><br>type<br>&nbsp; PNetResourceArray = ^TNetResourceArray;<br>&nbsp; TNetResourceArray = array[0..0] of TNetResource;<br><br>{ TNetworkItem }<br><br>constructor TNetworkItem.Create;<br>begin<br>&nbsp; inherited;<br>&nbsp; FSubItems := TNetworkItems.Create;<br>end;<br><br>destructor TNetworkItem.Destroy;<br>begin<br>&nbsp; if FSubItems &lt;&gt; nil then<br>&nbsp; &nbsp; FSubItems.Free;<br>&nbsp; inherited;<br>end;<br><br>{ TNetworkItems }<br><br>constructor TNetworkItems.Create;<br>begin<br>&nbsp; inherited;<br>&nbsp; FList := TList.Create;<br>end;<br><br>destructor TNetworkItems.Destroy;<br><br>begin<br>&nbsp; Clear;<br>&nbsp; if FList &lt;&gt; nil then<br>&nbsp; &nbsp; FList.Free;<br>&nbsp; inherited;<br>end;<br><br>procedure TNetworkItems.SetItem(Index: Integer; Value: TNetworkItem);<br>begin<br>&nbsp; if (FList.Items[Index] &lt;&gt; nil) and (FList.Items[Index] &lt;&gt; Value) then<br>&nbsp; &nbsp; TNetworkItem(FList.Items[Index]).Free;<br>&nbsp; FList.Items[Index] := Value;<br>end;<br><br>function TNetworkItems.GetItem(Index: Integer): TNetworkItem;<br>begin<br>&nbsp; Result := TNetworkItem(FList.Items[Index]);<br>end;<br><br>procedure TNetworkItems.Clear;<br>begin<br>&nbsp; while Count &gt; 0 do<br>&nbsp; &nbsp; Delete(0);<br>end;<br><br>procedure TNetworkItems.Add(Item: TNetworkItem);<br>begin<br><br>&nbsp; FList.Add(Item);<br>end;<br><br>procedure TNetworkItems.Delete(Index: Integer);<br>begin<br>&nbsp; if FList.Items[Index] &lt;&gt; nil then<br>&nbsp; &nbsp; TNetworkItem(FList.Items[Index]).Free;<br>&nbsp; FList.Delete(Index);<br>end;<br><br>function TNetworkItems.GetCount: Integer;<br>begin<br>&nbsp; if FList &lt;&gt; nil then<br>&nbsp; &nbsp; Result := FList.Count<br>&nbsp; else<br>&nbsp; &nbsp; Result := 0;<br>end;<br><br>{ TNetworkBrowser }<br><br>constructor TNetworkBrowser.Create(AOwner: TComponent);<br>begin<br>&nbsp; inherited Create(AOwner);<br>&nbsp; FItems := TNetworkItems.Create;<br>&nbsp; FScope := nsGlobal;<br>&nbsp; FResourceType := nrAny;<br>&nbsp; FUsage := [];<br>end;<br><br>destructor TNetworkBrowser.Destroy;<br>begin<br>&nbsp; if FItems &lt;&gt; nil then<br>&nbsp; &nbsp; FItems.Free;<br><br>&nbsp; inherited;<br>end;<br><br>procedure TNetworkBrowser.EnumerateNet(NetItems: TNetworkItems; lpnr:<br>PNetResource);<br>var<br>&nbsp; dwResult, dwResultEnum: Integer;<br>&nbsp; hEnum: THandle;<br>&nbsp; cbBuffer, cEntries, i: Integer;<br>&nbsp; nrArray: PNetResourceArray;<br>&nbsp; NewItem: TNetworkItem;<br>&nbsp; dwScope, dwType, dwUsage: Integer;<br>begin<br>&nbsp; cbBuffer := 16384;<br>&nbsp; cEntries := $FFFFFFFF;<br><br>&nbsp; case FScope of<br>&nbsp; &nbsp; nsConnected: dwScope := RESOURCE_CONNECTED;<br>&nbsp; &nbsp; nsGlobal: dwScope := RESOURCE_GLOBALNET;<br>&nbsp; &nbsp; nsRemembered: dwScope := RESOURCE_REMEMBERED;<br><br>&nbsp; &nbsp; nsContext: dwScope := RESOURCE_CONTEXT;<br>&nbsp; else<br>&nbsp; &nbsp; dwScope := RESOURCE_GLOBALNET;<br>&nbsp; end;<br>&nbsp; case FResourceType of<br>&nbsp; &nbsp; nrAny: dwType := RESOURCETYPE_ANY;<br>&nbsp; &nbsp; nrDisk: dwType := RESOURCETYPE_DISK;<br>&nbsp; &nbsp; nrPrint: dwType := RESOURCETYPE_PRINT;<br>&nbsp; else<br>&nbsp; &nbsp; dwType := RESOURCETYPE_ANY;<br>&nbsp; end;<br>&nbsp; dwUsage := 0;<br>&nbsp; if nuConnectable in FUsage then<br>&nbsp; &nbsp; dwUsage := dwUsage or RESOURCEUSAGE_CONNECTABLE;<br>&nbsp; if nuContainer in FUsage then<br>&nbsp; &nbsp; dwUsage := dwUsage or RESOURCEUSAGE_CONTAINER;<br><br>&nbsp; dwResult := WNetOpenEnum(dwScope, dwType, dwUsage, lpnr, hEnum);<br><br>&nbsp; if dwResult &lt;&gt; NO_ERROR then Exit;<br><br>&nbsp; GetMem(nrArray, cbBuffer);<br>&nbsp; repeat<br>&nbsp; &nbsp; dwResultEnum := WNetEnumResource(hEnum, cEntries, nrArray, cbBuffer);<br>&nbsp; &nbsp; if dwResultEnum = NO_ERROR then<br>&nbsp; &nbsp; &nbsp; for i := 0 to cEntries-1 do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; NewItem := TNetworkItem.Create;<br>&nbsp; &nbsp; &nbsp; &nbsp; case nrArray.dwScope of<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCE_CONNECTED: &nbsp;NewItem.FScope := nsConnected;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCE_GLOBALNET: &nbsp;NewItem.FScope := nsGlobal;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCE_REMEMBERED: NewItem.FScope := nsRemembered;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCE_CONTEXT: &nbsp; &nbsp;NewItem.FScope := nsContext;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NewItem.FScope := nsGlobal;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; case nrArray.dwType of<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCETYPE_ANY: &nbsp; NewItem.FResourceType := nrAny;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCETYPE_DISK: &nbsp;NewItem.FResourceType := nrDisk;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCETYPE_PRINT: NewItem.FResourceType := nrPrint;<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NewItem.FResourceType := nrAny;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; case nrArray.dwDisplayType of<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCEDISPLAYTYPE_GENERIC: &nbsp; &nbsp; &nbsp;NewItem.FDisplay := ndGeneric;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCEDISPLAYTYPE_DOMAIN: &nbsp; &nbsp; &nbsp; NewItem.FDisplay := ndDomain;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCEDISPLAYTYPE_SERVER: &nbsp; &nbsp; &nbsp; NewItem.FDisplay := ndServer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCEDISPLAYTYPE_SHARE: &nbsp; &nbsp; &nbsp; &nbsp;NewItem.FDisplay := ndShare;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCEDISPLAYTYPE_FILE: &nbsp; &nbsp; &nbsp; &nbsp; NewItem.FDisplay := ndFile;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCEDISPLAYTYPE_GROUP: &nbsp; &nbsp; &nbsp; &nbsp;NewItem.FDisplay := ndGroup;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCEDISPLAYTYPE_NETWORK: &nbsp; &nbsp; &nbsp;NewItem.FDisplay := ndNetwork;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCEDISPLAYTYPE_ROOT: &nbsp; &nbsp; &nbsp; &nbsp; NewItem.FDisplay := ndRoot;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCEDISPLAYTYPE_SHAREADMIN: &nbsp; NewItem.FDisplay :=<br><br>ndShareAdmin;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCEDISPLAYTYPE_DIRECTORY: &nbsp; &nbsp;NewItem.FDisplay :=<br>ndDirectory;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCEDISPLAYTYPE_TREE: &nbsp; &nbsp; &nbsp; &nbsp; NewItem.FDisplay := ndTree;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RESOURCEDISPLAYTYPE_NDSCONTAINER: NewItem.FDisplay :=<br>ndNDSContainer;<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NewItem.FDisplay := ndGeneric;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; NewItem.FUsage := [];<br>&nbsp; &nbsp; &nbsp; &nbsp; if nrArray.dwUsage and RESOURCEUSAGE_CONNECTABLE &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Include(NewItem.FUsage, nuConnectable);<br>&nbsp; &nbsp; &nbsp; &nbsp; if nrArray.dwUsage and RESOURCEUSAGE_CONTAINER &lt;&gt; 0 then<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Include(NewItem.FUsage, nuContainer);<br>&nbsp; &nbsp; &nbsp; &nbsp; NewItem.FLocalName := StrPas(nrArray.lpLocalName);<br>&nbsp; &nbsp; &nbsp; &nbsp; NewItem.FRemoteName := StrPas(nrArray.lpRemoteName);<br>&nbsp; &nbsp; &nbsp; &nbsp; NewItem.FComment := StrPas(nrArray.lpComment);<br>&nbsp; &nbsp; &nbsp; &nbsp; NewItem.FProvider := StrPas(nrArray.lpProvider);<br>&nbsp; &nbsp; &nbsp; &nbsp; NetItems.Add(NewItem);<br>&nbsp; &nbsp; &nbsp; &nbsp; // if container, call recursively<br>&nbsp; &nbsp; &nbsp; &nbsp; if (nuContainer in NewItem.FUsage) and (FScope &lt;&gt; nsContext) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EnumerateNet(NewItem.FSubItems, @nrArray)<br><br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; until dwResultEnum = ERROR_NO_MORE_ITEMS;<br><br>&nbsp; FreeMem(nrArray);<br>&nbsp; WNetCloseEnum(hEnum);<br>end;<br><br>procedure TNetworkBrowser.Refresh;<br>begin<br>&nbsp; FItems.Clear;<br>&nbsp; if FActive then<br>&nbsp; &nbsp; EnumerateNet(FItems, nil);<br>end;<br><br>procedure TNetworkBrowser.SetActive(Value: Boolean);<br>begin<br>&nbsp; if Value &lt;&gt; FActive then<br>&nbsp; begin<br>&nbsp; &nbsp; FActive := Value;<br>&nbsp; &nbsp; Refresh;<br>&nbsp; end;<br>end;<br><br>procedure TNetworkBrowser.SetScope(Value: TNetScope);<br>begin<br>&nbsp; if Value &lt;&gt; FScope then<br>&nbsp; begin<br>&nbsp; &nbsp; FScope := Value;<br>&nbsp; &nbsp; Refresh;<br>&nbsp; end;<br>end;<br><br>&nbsp;<br>procedure TNetworkBrowser.SetResourceType(Value: TNetResourceType);<br>begin<br>&nbsp; if Value &lt;&gt; FResourceType then<br>&nbsp; begin<br>&nbsp; &nbsp; FResourceType := Value;<br>&nbsp; &nbsp; Refresh;<br>&nbsp; end;<br>end;<br><br>procedure TNetworkBrowser.SetUsage(Value: TNetUsage);<br>begin<br>&nbsp; if Value &lt;&gt; FUsage then<br>&nbsp; begin<br>&nbsp; &nbsp; FUsage := Value;<br>&nbsp; &nbsp; Refresh;<br>&nbsp; end;<br>end;<br><br>procedure TNetworkBrowser.Open;<br>begin<br>&nbsp; Active := True;<br>end;<br><br>procedure TNetworkBrowser.Close;<br>begin<br>&nbsp; Active := False;<br>end;<br><br>end.<br><br><br><br>----------------------------------------------------------<br><br><br>unit FindComp; <br><br>&nbsp;<br><br>interface <br><br>&nbsp;<br><br>uses <br><br>&nbsp; Windows, Classes; <br><br>&nbsp;<br><br>function FindComputers: DWORD; <br><br>&nbsp;<br><br>var <br><br>&nbsp; Computers: TStringList; <br><br>&nbsp;<br><br>implementation <br><br>&nbsp;<br><br>uses <br><br>&nbsp; SysUtils; <br><br>&nbsp;<br><br>const <br><br>&nbsp; MaxEntries = 250; <br><br>&nbsp;<br><br>function FindComputers: DWORD; <br><br>&nbsp;<br><br>var <br><br>&nbsp; EnumWorkGroupHandle, EnumComputerHandle: THandle; <br><br>&nbsp; EnumError: DWORD; <br><br>&nbsp; Network: TNetResource; <br><br>&nbsp; WorkGroupEntries, ComputerEntries: DWORD; <br><br>&nbsp; EnumWorkGroupBuffer, EnumComputerBuffer: array[1..MaxEntries] of TNetResource; <br><br>&nbsp; EnumBufferLength: DWORD; <br><br>&nbsp; I, J: DWORD; <br><br>&nbsp;<br><br>begin <br><br>&nbsp;<br><br>&nbsp; Computers.Clear; <br><br>&nbsp;<br><br>&nbsp; FillChar(Network, SizeOf(Network), 0); <br><br>&nbsp; with Network do <br><br>&nbsp; begin <br><br>&nbsp; dwScope := RESOURCE_GLOBALNET; <br><br>&nbsp; dwType := RESOURCETYPE_ANY; <br><br>&nbsp; dwUsage := RESOURCEUSAGE_CONTAINER; <br><br>&nbsp; end; <br><br>&nbsp; <br><br>&nbsp; EnumError := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, @Network, EnumWorkGroupHandle); <br><br>&nbsp;<br><br>&nbsp; if EnumError = NO_ERROR then <br><br>&nbsp; begin <br><br>&nbsp; WorkGroupEntries := MaxEntries; <br><br>&nbsp; EnumBufferLength := SizeOf(EnumWorkGroupBuffer); <br><br>&nbsp; EnumError := WNetEnumResource(EnumWorkGroupHandle, WorkGroupEntries, @EnumWorkGroupBuffer, EnumBufferLength); <br><br>&nbsp;<br><br>&nbsp; if EnumError = NO_ERROR then <br><br>&nbsp; begin <br><br>&nbsp; for I := 1 to WorkGroupEntries do <br><br>&nbsp; begin <br><br>&nbsp; EnumError := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, @EnumWorkGroupBuffer, EnumComputerHandle); <br><br>&nbsp; if EnumError = NO_ERROR then <br><br>&nbsp; begin <br><br>&nbsp; ComputerEntries := MaxEntries; <br><br>&nbsp; EnumBufferLength := SizeOf(EnumComputerBuffer); <br><br>&nbsp; EnumError := WNetEnumResource(EnumComputerHandle, ComputerEntries, @EnumComputerBuffer, EnumBufferLength); <br><br>&nbsp; if EnumError = NO_ERROR then <br><br>&nbsp; for J := 1 to ComputerEntries do <br><br>&nbsp; Computers.Add(Copy(EnumComputerBuffer[J].lpRemoteName, 3, Length(EnumComputerBuffer[J].lpRemoteName) - 2)); <br><br>&nbsp; WNetCloseEnum(EnumComputerHandle); <br><br>&nbsp; end; <br><br>&nbsp; end; <br><br>&nbsp; end; <br><br>&nbsp; WNetCloseEnum(EnumWorkGroupHandle); <br><br>&nbsp; end; <br><br>&nbsp;<br><br>&nbsp; if EnumError = ERROR_NO_MORE_ITEMS then <br><br>&nbsp; EnumError := NO_ERROR; <br><br>&nbsp; Result := EnumError; <br><br>end; <br><br>&nbsp;<br><br>initialization <br><br>&nbsp; Computers := TStringList.Create; <br><br>finalization <br><br>&nbsp; Computers.Free; <br><br>end. <br><br>&nbsp; <br>
 
新办法!<br>用WINDOWS自带的程序命令即可<br>办法如下:<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>VAR<br>&nbsp; &nbsp; command:string ;<br>&nbsp; &nbsp; comline: pchar &nbsp;;<br>begin<br>&nbsp;command:='COMMAND.COM /C net view&gt;c:/~~~.txt';<br>&nbsp;comline:=pchar(command);<br>&nbsp;WinExec(comline, sw_hide);<br>&nbsp;timer1.Enabled:=true;<br>end;<br><br>每秒试一次<br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var f:tstringlist;<br>&nbsp; &nbsp; ll,ii:integer;<br>&nbsp; &nbsp; s1,s:string;<br>&nbsp; &nbsp; b:bool;<br>begin<br>f:=tstringlist.Create;<br>try<br>&nbsp; f.LoadFromFile('c:/~~~.txt');<br>&nbsp;except<br>end;<br>if &nbsp;f.Count&gt;10 then begin<br>memo1.Clear;<br>memo1.lines.add(f.text); <br>timer1.Enabled:=false;<br>f.Free;<br>{去掉多余的行和'//'}<br>&nbsp; for ll:=memo1.lines.count-1 downto 0 do begin<br>&nbsp; &nbsp; &nbsp;if strpos(pchar(memo1.lines.strings[ll]),'//')=nil then<br>&nbsp; &nbsp; &nbsp; &nbsp;memo1.lines.delete(ll)<br>&nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp;memo1.lines.Strings[ll]:=delxxx(memo1.lines.Strings[ll]);<br>&nbsp; &nbsp; &nbsp; &nbsp; {自编1个去'//'的函数}<br>&nbsp; end;<br>timer1.enabled:=False;<br>end;
 
获得网络邻居中所有机器名!<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>VAR<br>&nbsp; &nbsp; command:string ;<br>&nbsp; &nbsp; comline: pchar &nbsp;;<br>begin<br>&nbsp;command:='COMMAND.COM /C net view&gt;c:/~~~.txt';<br>&nbsp;comline:=pchar(command);<br>&nbsp;WinExec(comline, sw_hide);<br>&nbsp;timer1.Enabled:=true;<br>end;<br><br>//每秒试一次<br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var f:tstringlist;<br>&nbsp; &nbsp; ll,ii:integer;<br>&nbsp; &nbsp; s1,s:string;<br>&nbsp; &nbsp; b:bool;<br>begin<br>f:=tstringlist.Create;<br>try<br>&nbsp; f.LoadFromFile('c:/~~~.txt');<br>&nbsp;except<br>end;<br>if &nbsp;f.Count&gt;10 then begin<br>memo1.Clear;<br>memo1.lines.add(f.text); <br>timer1.Enabled:=false;<br>f.Free;<br>//去掉多余的行和'//'<br>&nbsp; for ll:=memo1.lines.count-1 downto 0 do begin<br>&nbsp; &nbsp; &nbsp;if strpos(pchar(memo1.lines.strings[ll]),'//')=nil then<br>&nbsp; &nbsp; &nbsp; &nbsp;memo1.lines.delete(ll)<br>&nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp;memo1.lines.Strings[ll]:=delspace(memo1.lines.Strings[ll]);<br>&nbsp; end;<br>timer1.enabled:=False;<br>end;<br>
 
多人接受答案了。
 
后退
顶部