Solved

List computers in local network

Posted on 1999-01-28
6
266 Views
Last Modified: 2010-04-06
How can I list the computers that are on my local network in my Delphi app?
"FindFirst('\\*.*', faAnyFile, SearchRec);" doesn't find anything.
0
Comment
Question by:friberg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 7

Expert Comment

by:BlackMan
ID: 1363638
Here's an example that lists all computers in the WORKGROUP workgroup. If you want to use the example directly, you need a form with a TListBox called LB.
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_GLOBALNET;
    dwType:=RESOURCETYPE_DISK;
    dwDisplayType:=RESOURCEDISPLAYTYPE_SHARE;
    dwUsage:=0;
    lpLocalName:='';
    lpRemoteName:=PChar(Name);
    lpComment:='';
    lpProvider:='Microsoft Windows Network';
  End;
  CurrentPlace:='';
  NEResult:=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_DISK,0,@Rec,NEHandle);
{ Open enumeration, all resources, only disk, and no printers }
  if NEResult=0 then
  begin
    BufSize:=SizeOf(Temp);
    repeat
      MaxRecs:=10;
      NEResult:=WNetEnumResource(NEHandle,MaxRecs,@Temp,BufSize);
      if (NEResult=NO_ERROR) or (NEResult=ERROR_NO_MORE_ITEMS) then
      begin
For I:=0 to MaxRecs-1 do
  LB.Items.Add(Temp[I].lpremoteName);
      end;
    until NEResult<>NO_ERROR;
    if NEResult=ERROR_NO_MORE_ITEMS then
      WNetCloseEnum(NEHandle);
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  Scan('WORKGROUP');
end;

0
 

Author Comment

by:friberg
ID: 1363639
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?
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1363640
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 ('')
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Expert Comment

by:BlackMan
ID: 1363641
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 ('')
0
 

Author Comment

by:friberg
ID: 1363642
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?

0
 
LVL 7

Accepted Solution

by:
BlackMan earned 50 total points
ID: 1363643
Take a look a WNetOpenEnum in the Win32 help, there's a description of the different ways you can use it...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question