1

Using a UNC path such as \\1.2.3.4\drive\dir\myfile.txt I can access files on a remote machine. I can make a connection using WNetAddConnection2 programatically or I can just type \\1.2.3.4\ in the explorer address bar, and then Windows will prompt me for user credentials etc.

How can I list the UNC drives that the local machine is connected to for the current user?

I tried this example using WNetEnumResource - it lists nothing I find useful.

I also found this example using NetShareEnum, but it seems only to list who is connected to a specified remote machine.

I want to list all UNC drives that the local machine is connected to (which must not have necessarily have a local drive letter). How can that be done?

Kevin M. Mansour
  • 2,915
  • 6
  • 18
  • 35
RED SOFT ADAIR
  • 12,032
  • 10
  • 54
  • 92
  • Network shares are a per-user configuration, not per system which you seem to expect. – IInspectable Feb 04 '21 at 10:51
  • You are right, thats what i want (connections for the current user) - i clarified my post accordingly. – RED SOFT ADAIR Feb 04 '21 at 10:56
  • What about `WNetEnumResource()` doesn't work for you? "*`RESOURCE_CONNECTED` - Enumerate all currently connected resources*", sounds like exactly what you are looking for. Please show the actual code you have tried so far. – Remy Lebeau Feb 04 '21 at 19:20
  • Used the code of the linked sample - it doesnt show shared drives. I also tried RESOURCE_CONNECTED. – RED SOFT ADAIR Feb 04 '21 at 20:46
  • Do you mean to list such [drives](https://i.stack.imgur.com/STQaO.png)? [GetDriveType](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdrivetypea) can list network drive. – Strive Sun Feb 05 '21 at 09:01
  • It wont LIST such entries. I have to pass a directory / drive letter. – RED SOFT ADAIR Feb 05 '21 at 09:10
  • I still don't understand your question. Please update some images or code to describe the drive letter or directory you need. – Strive Sun Feb 07 '21 at 07:59

0 Answers0