0

I want to search for shared folders / drives in a local network.

A machine on the network has a folder shared, and it's mapped to the drive letter "X:\"

Another machine on the network has a folder shared, and it's mapped to the drive letter "Y:\".

On a third machine, I'm looking for a method to iterate through all folder / drives shared on this network. This method would list these 2 drives / folders.

So far, I haven't been able to find any function / method that would return these 2 shared folders.

What would be the way to iterate through the shared folders or network drives?

Thank you!

tmighty
  • 10,734
  • 21
  • 104
  • 218
  • 1
    Network shares are listed by the machine that shares them. You're talking about looking up every possible hostname on the network and asking each one for all of it's shared folders until you find the one you're looking for. – Joel Coehoorn Sep 24 '18 at 20:43
  • @JoelCoehoorn Yes, that's what I meant. – tmighty Sep 24 '18 at 20:48
  • You know that "every possible hostname" is an infinite set, right? – Joel Coehoorn Sep 24 '18 at 20:50
  • @JoelCoehoorn I mean "each present one". I want to search among each computer / host in my local network. – tmighty Sep 24 '18 at 20:52
  • What do you want to do this with this share once you find it? – Joel Coehoorn Sep 24 '18 at 20:53
  • I want to connect to a database that is in this shared folder. – tmighty Sep 24 '18 at 20:54
  • With the edit, it looks like you have the hostname already. Have you tried just opening the database with the UNC path you have? – Joel Coehoorn Sep 24 '18 at 20:54
  • No, I don't know the hostname. In Windows Explorer, I would click "Network" and then have a look at each machine listed there and expand it to see if there's this certain shared folder. – tmighty Sep 24 '18 at 20:56
  • "**`WIN-AJUUS3V93E5`**" is the host name. – Joel Coehoorn Sep 24 '18 at 20:56
  • Yes, but in reality, I don't know this host name. – tmighty Sep 24 '18 at 20:58
  • Is [SMBv1 still on](https://superuser.com/questions/1322497/did-windows-10-april-update-break-network-discovery-and-samba-support/1322727)? And what do you want to do if more than one host on the network has this share? – Joel Coehoorn Sep 24 '18 at 20:58
  • I don't have any SMB issues. It wouldn't be a problem if more than 1 share with the same name is found. I have updated my posting and given the folder a better name, say I want to find the share "MyShare" – tmighty Sep 24 '18 at 21:01
  • You certainly do have SMB issues if SMBv1 is still active; you just haven't noticed them yet. And there's good odds that's what's powering the "Network" view you see right now. For the other part, you're saying you really don't care if you connect to the wrong database? – Joel Coehoorn Sep 24 '18 at 21:04
  • I'm not familiar with SMB. In the case of more than 1 share with the same name, I would prompt the user an error message. – tmighty Sep 24 '18 at 21:05
  • But how would you know there's more than one without checking an potentially infinite number of possible hosts, of which the hosts actually online at a given moment can change frequently? You really out to set a known host for this. This is why we use servers. – Joel Coehoorn Sep 24 '18 at 21:06
  • I would take care of this problem later. I would first like to get the grasp of doing this "infinite checking" and do the refinement / changes later. Would GetDrives normally return these network shares / drives, and the reason why I'm NOT seeing them is caused by SMBv1? – tmighty Sep 24 '18 at 21:09
  • No. You don't see it because it's not mapped as a drive for the user account running the check. "infinite checking" means sitting there and potentially never getting a response. – Joel Coehoorn Sep 24 '18 at 21:13
  • Thank you, I will do that first. – tmighty Sep 24 '18 at 21:19
  • @JoelCoehoorn I have it mapped to a drive letter now, however it doesn't show up when I call GetDrives from the other machine. – tmighty Sep 25 '18 at 01:51
  • "the other machine"? `GetDrives` will return logical drives on the machine you're running the code on, for the user that owns the process. So if on machine A you map a network share on machine B to a drive letter, running GetDrives on A should list it, running it on B won't. Please be explicit when you're describing what you're trying. – Lasse V. Karlsen Sep 25 '18 at 12:20
  • To find all machines on the network, there's an existing question here: https://stackoverflow.com/questions/2557551/how-get-list-of-local-network-computers – Lasse V. Karlsen Sep 25 '18 at 12:21
  • To get a list of network shares for a remote computer, there's an existing question here: https://stackoverflow.com/questions/3567063/get-a-list-of-all-unc-shared-folders-on-a-local-network-server – Lasse V. Karlsen Sep 25 '18 at 12:23

0 Answers0