How to get the free disk space oon the server

  • Thread starter Thread starter Anna
  • Start date Start date
This is easy using System.Management and WMI.
Here's is a sample:

using System;
using System.Management;
class Tester {
public static void Main() {
GetFreeSpace(@"\\\\myserverName\\d$");
}
public static void GetFreeSpace(string ProviderName )
{
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(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.
 
Back
Top