Link to home
Start Free TrialLog in
Avatar of john-6789
john-6789

asked on

How to search for shared folders in LAN using delphi

Hello,,

i need to search the local network for search and list the shared folders,
and how to copy them to my pc.

best regards,

Avatar of Emmanuel PASQUIER
Emmanuel PASQUIER
Flag of France image

You can check in the list of all network resources available, here is how to get that list

Call it :
EnumNetworkResources(nil, lbNetworkDrive.Items );
procedure EnumNetworkResources(NetResource: PNEtResource; List: TStrings);
var
 EnumHandle, Count, BufSize, I: Cardinal;
 NetArray: array[0..250] of TNetResource;
begin
 if WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, NetResource,EnumHandle) = NO_ERROR then
  try
   Count := $FFFFFFFF;
   BufSize := SizeOf(NetArray);
   if WNetEnumResource(EnumHandle, Count, @NetArray, BufSize) = NO_ERROR then
    begin
     for i := 0 to Count -1 do
      begin
       if NetArray[i].dwType=RESOURCETYPE_DISK Then List.Add(NetArray[i].lpRemoteName);
       EnumNetworkResources(@NetArray[i], List);
      end;
    end;
  finally
   WNetCloseEnum(EnumHandle);
  end;
end;

Open in new window

please download the project file I attached and try
SearchShareNetworkList.zip
Hi systan ! How goes

Don't you find it a bit rude to kill the application if there is no shared folders ?
in NetCheck :
if csl<=0 then application.Terminate; 

Open in new window


Another note, your code would gain a lot by being indented.
oh, hi epasquier, glad you've talk
am, actually it depends on the user where and when they want to terminate
but i think the project pointed the right direction
indented? yep, it can be change.
thanks
indented? yep, it can be change.

Open in new window

Well, it's more a counsel for you, as if you get that habit to indent properly the code, you'll see that your skills will improve dramatically as it has a strong effect on how you can organize your code, and how fast you can travel through it to add features.

And for expert exchange, it helps a lot other readers
>systan
ouch my eyes, but you was expecting,
i'm not givin any comments on that collection of letters and numbers which are supposed to be code
Geert : you are lacking a bit of education, this is not a way to talk to ladies ;o)
but since you are only emphasizing my thoughts, I'll forgive you.
hi guys
do you know, that im far away from both of you.
im trying to get points here, lol
you know i struggle to become a delphi guru, because im lazy and forgetful.
anyway,  forgive the way i code,   time will come, ill be like both of you.
most important in this post,  the asker got what it needs.
Avatar of john-6789
john-6789

ASKER

systan:

the example project work ok but only for winxp , the process terminated afiter a while in win7.

Ok, try to remove this line,
if csl<=0 then application.Terminate;
hi
I have borrowed a pc with windows 7 x86 32bit, I have no problem viewing the shared folders on the network.
I also remove that line.
ASKER CERTIFIED SOLUTION
Avatar of Emmanuel PASQUIER
Emmanuel PASQUIER
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
my bad, I forgot to remove something along the way. Thank you for noting it, systan
Men, I though this was closed
Well, at least there is not much more to say or code to write
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
thank you