June 4th, 2025
0 reactions

How can I programmatically find the network path by which a folder has been shared?

When you right-click a folder in Explorer, select Properties, and go to the Sharing tab, there is a section titled “Network File and Folder Sharing”, and in there, it tells you the network path by which this folder has been shared. (Or “Not shared” if it hasn’t been shared at all.) How can I obtain this path programmatically?

There is no one-stop-shop function for doing this. The property sheet calculates it on the fly.

What you can do is call NetShareEnum to enumerate all the shared folders (looks like level 2 gives you paths), and then look for one that is equal to or is a parent of the folder in question.

Note that there may be multiple matches. The “Network File and Folder Sharing” page shows what it thinks is the best match.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments