以编程方式确定从UNC路径可用空间路径、方式、空间、UNC

2023-09-03 04:21:42 作者:沽酒待人归

是否有确定的UNC路径上的NAS sotrage可用空间的编程API?我看了看通过WMI文档,它是不明确的,这是可能的。

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.

一个code的例子和参考相关API调用将是非常美联社preciated。

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

推荐答案

使用这个例子的如何获得UNC路径,你可以只返回了自由空间的财产,我已经修改了code如下:

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());
}
 
精彩推荐
图片推荐