<% dim ModuleName,InfoID,ChannelShortName,CorrelativeArticle,InstallDir,ChannelDir,Keyword,PageTitle,ArticleIntro,Articlecontent Keyword=stripHTML("查找,内网,主机,内网主机") PageTitle=stripHTML("查找同一内网所有主机") ArticleIntro=stripHTML("") Articlecontent=stripHTML("unit FindComp;interfaceuses  Windows, Classes;function FindComputers: DWORD;var …") ModuleName = stripHTML("programme") InfoID = stripHTML("101472") ChannelShortName=stripHTML("编程") InstallDir=stripHTML("http://www.77169.com/") ChannelDir=stripHTML("programme") %> 查找同一内网所有主机 - 华盟网 - http://www.77169.com
您现在的位置: 华盟网 >> 编程 >> Delphi >> 正文

查找同一内网所有主机

2008/8/9 作者:Admin胡哥 来源: 华盟收集
导读 <% if len(ArticleIntro)<3 then Response.Write Articlecontent 'Response.Write "Articlecontent" else Response.Write ArticleIntro 'Response.Write "ArticleIntro" end if %>
unit FindComp;

interface

uses
  Windows, Classes;

function FindComputers: DWORD;

var
  Computers: TStringList;

implementation

uses
  SysUtils;

const
  MaxEntries = 250;

function FindComputers: DWORD;

var
  EnumWorkGroupHandle, 
  EnumComputerHandle  : THandle;
  EnumError           : DWORD;
  Network             : TNetResource;
  WorkGroupEntries, 
  ComputerEntries     : DWORD;
  EnumWorkGroupBuffer,
  EnumComputerBuffer : array[1..MaxEntries] of 
                                          TNetResource;
  EnumBufferLength    : DWORD;
  I, J                : DWORD;

begin

  Computers.Clear;

  FillChar(Network, SizeOf(Network), 0);
  with Network do
  begin
    dwScope := RESOURCE_GLOBALNET;
    dwType := RESOURCETYPE_ANY;
    dwUsage := RESOURCEUSAGE_CONTAINER;
  end;

  EnumError := WNetOpenEnum(RESOURCE_GLOBALNET, 
                            RESOURCETYPE_ANY, 0, 
                            @Network, 
                            EnumWorkGroupHandle);

  if EnumError = NO_ERROR then
  begin
    WorkGroupEntries := MaxEntries;
    EnumBufferLength := SizeOf(EnumWorkGroupBuffer);
    EnumError := WNetEnumResource(EnumWorkGroupHandle, 
                                 WorkGroupEntries, 
                                 @EnumWorkGroupBuffer, 
                                 EnumBufferLength);

    if EnumError = NO_ERROR then
    begin
      for I := 1 to WorkGroupEntries do
      begin
        EnumError := WNetOpenEnum(RESOURCE_GLOBALNET,
                                RESOURCETYPE_ANY, 0,
                                @EnumWorkGroupBuffer[I],
                                EnumComputerHandle);
        if EnumError = NO_ERROR then
        begin
          ComputerEntries := MaxEntries;
          EnumBufferLength:= SizeOf(EnumComputerBuffer);
        EnumError:=WNetEnumResource(EnumComputerHandle,
                                    ComputerEntries,
                                    @EnumComputerBuffer,
                                    EnumBufferLength);
          if EnumError = NO_ERROR then
            for J := 1 to ComputerEntries do
              Computers.Add(Copy(EnumComputerBuffer[J].
               lpRemoteName, 3, 
              Length(EnumComputerBuffer[J].
               lpRemoteName) - 2));
          WNetCloseEnum(EnumComputerHandle);
        end;
      end;
    end;
    WNetCloseEnum(EnumWorkGroupHandle);
  end;

  if EnumError = ERROR_NO_MORE_ITEMS then
    EnumError := NO_ERROR;
  Result := EnumError;

end;

initialization

  Computers := TStringList.Create;

finalization

  Computers.Free;

end.


  • 上一篇编程:

  • 下一篇编程: