friberg
asked on
List computers in local network
How can I list the computers that are on my local network in my Delphi app?
"FindFirst('\\*.*', faAnyFile, SearchRec);" doesn't find anything.
"FindFirst('\\*.*', faAnyFile, SearchRec);" doesn't find anything.
ASKER
BlackMan, thanks but I couldn't get it to work. NEResult=1204 and the procedure exits, although I have typed my WorkGroup name correctly. When I click on the Network icon on my desktop, I see almost 400 computers. Any suggestions?
1204 means "Bad Network Provider", I guess you are not running a US language OS?
Type to set lpProvider to either the name you can see in the Explorer under Network / Entire Network or just leave it blank ('')
Type to set lpProvider to either the name you can see in the Explorer under Network / Entire Network or just leave it blank ('')
1204 means "Bad Network Provider", I guess you are not running a US language OS?
Try to set lpProvider to either the name you can see in the Explorer under Network / Entire Network or just leave it blank ('')
Try to set lpProvider to either the name you can see in the Explorer under Network / Entire Network or just leave it blank ('')
ASKER
Thanks, I set it to '' and now it works. I run the Swedish version of Win98, so that must have been the reason. Could you please submit it as an answer?
By the way, I can see 37 other networks if I click on Entire Network. Maybe you could help me to list these in Delphi too, so that I will be able to scan each one of them?
By the way, I can see 37 other networks if I click on Entire Network. Maybe you could help me to list these in Delphi too, so that I will be able to scan each one of them?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The code is for D4, change DWORD to Integer if you are using D2/D3..
Var
CurrentPlace : String;
I : Integer;
type
TNetRecArr = Array[0..9] of TNetResourceA;
procedure tform1.Scan(Name: String);
var
Rec: TNetResourceA;
Temp: TNetRecArr;
NEHandle,
NEResult,
MaxRecs,
BufSize: dword;
begin
With Rec do
begin
dwScope:=RESOURCE_GLOBALNE
dwType:=RESOURCETYPE_DISK;
dwDisplayType:=RESOURCEDIS
dwUsage:=0;
lpLocalName:='';
lpRemoteName:=PChar(Name);
lpComment:='';
lpProvider:='Microsoft Windows Network';
End;
CurrentPlace:='';
NEResult:=WNetOpenEnum(RES
{ Open enumeration, all resources, only disk, and no printers }
if NEResult=0 then
begin
BufSize:=SizeOf(Temp);
repeat
MaxRecs:=10;
NEResult:=WNetEnumResource
if (NEResult=NO_ERROR) or (NEResult=ERROR_NO_MORE_IT
begin
For I:=0 to MaxRecs-1 do
LB.Items.Add(Temp[I].lprem
end;
until NEResult<>NO_ERROR;
if NEResult=ERROR_NO_MORE_ITE
WNetCloseEnum(NEHandle);
end;
end;
procedure TForm1.Button1Click(Sender
begin
Scan('WORKGROUP');
end;