开发者

Programmatically determining space available from UNC Path

开发者 https://www.devze.com 2022-12-16 07:26 出处:网络
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.

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());
}
0

精彩评论

暂无评论...
验证码 换一张
取 消