title: How to get a list with all computers from the local network?
body: <p>This code I've got a long time ago was supposed to return a string list with each computer connected to my Windows <code>workgroup</code> but when I tested I get only my own computer, but I have three computers connected with the same <code>workgroup</code> name and appearing in my Windows Explorer Network List.</p>
  
  <p>What could be wrong? Is there another way to do it?</p>
  
  <pre><code>function FindAllComputers(Workgroup: string; WithIP: Boolean): TStringList;
  var
    EnumHandle : THandle;
    WorkgroupRS : TNetResource;
    Buf : Array[1..500] of TNetResource;
    BufSize : cardinal;
    Entries : cardinal;
    Res : Integer;
    Computers : Tstringlist;
    Limit, I: Integer;
  begin
    Limit := 0;
    Workgroup := Workgroup + #0;
    FillChar(WorkgroupRS, SizeOf(WorkgroupRS) , 0);
    With WorkgroupRS do
    begin
      dwScope := 2;
      dwType := 3;
      dwDisplayType := 1;
      dwUsage := 2;
      lpRemoteName := @Workgroup[1];
    end;
    WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, 
      @WorkgroupRS, EnumHandle);
    Computers := TStringList.Create;
    repeat
      Entries := 1;
      BufSize := SizeOf(Buf);
      Res := WNetEnumResource(EnumHandle, Entries, @Buf, BufSize);
      if (Res = NO_ERROR) and (Entries = 1) then
      begin
        Computers.Add(StrPas(Buf[1].lpRemoteName));
      end;
      Inc(Limit);
    until (Entries &gt; 0) or (Res &lt;&gt; NO_ERROR) or (Limit &gt; 100);
    WNetCloseEnum( EnumHandle );
    if WithIP then
    begin
      for I := 0 to Computers.Count-1 do
        Computers[I] := Computers[I] + '=' + GetIP(Computers[I]);
    end;
    Result := Computers;
  end;
  </code></pre>