tags:

views:

269

answers:

2

Is there a programmatic API for determining available space on NAS sotrage from a UNC path? I looked through the WMI documentation and it wasn't clear that this is possible.

A code example and references to the relevant API calls would be much appreciated.

A: 

In the windows API, GetFreeDiskSpaceEx seems to be the method to use, which works on UNC paths according to the MSDN docs.

dsolimano
A: 

Using this example on how to get the UNC path, you could just return the FreeSpace property, I've modified the code below:

ManagementPath path = new ManagementPath(@"\" + System.Environment.MachineName + @"\root\cimv2");
ObjectQuery query = new ObjectQuery("select * from Win32_LogicalDisk WHERE DriveType = 4");
ManagementScope scope = new ManagementScope(path, new ConnectionOptions());
ManagementObjectSearcher search = new ManagementObjectSearcher(scope, query);

foreach (ManagementObject o in search.Get())
{
    Console.WriteLine(o.Properties["FreeSpace"].Value.ToString());
}
taylonr