Mega Code Archive

 
Categories / Delphi / LAN Web TCP
 

Get list of names of all computers within your workgroup

Title: Get list of names of all computers within your workgroup Question: I've seen on this site articles about finding all computers within your network... by reading from registry... But in real this only cached computer names :) Use this code below to fetch list of names of all computers within your workgroup. Code from http://igp.org.ua/articles/a26/ Answer: var Computer : Array[1..500] of String[25]; ComputerCount : Integer; procedure FindAllComputers(Workgroup: String); var EnumHandle : THandle; WorkgroupRS : TNetResource; Buf : Array[1..500] of TNetResource; BufSize : Integer; Entries : Integer; Result : Integer; begin ComputerCount := 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 ); Repeat Entries := 1!; BufSize := SizeOf(Buf); Result := WNetEnumResource( EnumHandle, Entries,@Buf, BufSize ); If (Result = NO_ERROR) and (Entries = 1) then begin Inc( ComputerCount); Computer[ ComputerCount ] := StrPas(Buf[1].lpRemoteName); end; Until (Entries 1) or (Result NO_ERROR); WNetCloseEnum( EnumHandle ); end; { Find All Computers }