Solved

List computers in local network

Posted on 1999-01-28
6
263 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

772 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