Author: Erwin Molendijk Finding all computers in a workgroup. Answer: 1 var 2 Computer: array[1..500] of string[25]; 3 ComputerCount: Integer; 4 5 procedure FindAllComputers(Workgroup: string); 6 var 7 EnumHandle: THandle; 8 WorkgroupRS: TNetResource; 9 Buf: array[1..500] of TNetResource; 10 BufSize: Integer; 11 Entries: Integer; 12 Result: Integer; 13 14 begin 15 ComputerCount := 0; 16 17 Workgroup := Workgroup + #0; 18 19 FillChar(WorkgroupRS, SizeOf(WorkgroupRS), 0); 20 with WorkgroupRS do 21 begin 22 dwScope := 2; 23 dwType := 3; 24 dwDisplayType := 1; 25 dwUsage := 2; 26 lpRemoteName := @Workgroup[1]; 27 end; 28 29 WNetOpenEnum(RESOURCE_GLOBALNET, 30 RESOURCETYPE_ANY, 31 0, 32 @WorkgroupRS, 33 EnumHandle); 34 35 repeat 36 Entries := 1; 37 BufSize := SizeOf(Buf); 38 39 Result := 40 WNetEnumResource(EnumHandle, 41 Entries, 42 @Buf, 43 BufSize); 44 if (Result = NO_ERROR) and (Entries = 1) then 45 begin 46 Inc(ComputerCount); 47 Computer[ComputerCount] := StrPas(Buf[1].lpRemoteName); 48 end; 49 until (Entries <> 1) or (Result <> NO_ERROR); 50 51 WNetCloseEnum(EnumHandle); 52 end; { Find All Computers }