Is there a programmatic API for determining available space on NAS storage from a UNC path? I looked through the开发者_StackOverflow社区 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.
In the windows API, GetFreeDiskSpaceEx seems to be the method to use, which works on UNC paths according to the MSDN docs.
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());
}
精彩评论