Here is how to get the free space of a networked drive using
System.Management and WMI.
It's important to note that the free space could be incorrect when
user-quotas are applied.
using System;
using System.Management;
class Tester {
public static void Main() {
GetFreeSpace(@"\\\\scenic\\kdrive");
}
public static void GetFreeSpace(string ProviderName )
{
// Needs XP or higher
String strSQL = "SELECT FreeSpace, QuotasDisabled ,VolumeName FROM
Win32_LogicalDisk WHERE providername='" + ProviderName + "'" ;
SelectQuery query = new SelectQuery(strSQL);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject mo in searcher.Get()) {
// If both properties are null I suppose there's no CD
if(mo["QuotasDisabled"].ToString() != "true")
Console.WriteLine("{0} - Free bytes: {1} ",mo["VolumeName"],
mo["Freespace"]);
else
Console.WriteLine("{0} - Free bytes: {1} per-user quota's
applied!!",mo["VolumeName"], mo["Freespace"]);
}
}
}
Willy.