2010-01-12 60 views

回答

-2

如何獲得UNC路徑使用this example,你可以只返回FreeSpace屬性,我修改代碼如下:

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

我覺得這隻能如果已經「映射」的UNC路徑到邏輯磁盤(帶有盤符,例如Z :)。如果您想檢查未映射的服務器上的可用空間,該怎麼辦? – CyberMonk 2011-05-06 16:19:10