Get a list of all UNC shared folders on a local network server

Here’s a technique that uses System.Management (add a reference to this assembly):

using (ManagementClass shares = new ManagementClass(@"\\NameOfTheRemoteComputer\root\cimv2", "Win32_Share", new ObjectGetOptions())) {
    foreach (ManagementObject share in shares.GetInstances()) {
        Console.WriteLine(share["Name"]);
    }
}

Appropriate permissions are required.

Leave a Comment