Title: Enumerating workgroups on your LAN.
Question: Enumerating workgroups on your LAN.
Answer:
{ This code is a copy-paste from a working application.
}
var
WorkgroupCount : Integer;
Workgroup : Array[1..500] of String[25];
procedure FindAllWorkgroups;
Var
EnumHandle : THandle;
EntireNetwork : TNetResource;
Buf : Array[1..500] of TNetResource;
BufSize : Integer; // or DWORD;
Entries : Integer; // or DWORD;
begin
FillChar(EntireNetwork, SizeOf(EntireNetwork) , 0);
With EntireNetwork do begin
dwScope := 2;
dwDisplayType := 6;
dwUsage := 2;
end;
WNetOpenEnum( RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
@EntireNetwork,
EnumHandle );
WorkgroupCount := 0;
Repeat
Entries := 1;
BufSize := SizeOf(Buf);
WNetEnumResource( EnumHandle,
Entries,
@Buf,
BufSize );
If Entries = 1 then begin
Inc( WorkgroupCount );
Workgroup[ WorkgroupCount ] := StrPas(Buf[1].lpRemoteName);
end;
Until (Entries 1);
WNetCloseEnum( EnumHandle );
end;