Solved

List computers in local network

Posted on 1999-01-28
6
260 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
  • 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now