Here is how to get the free space of a networked drive using
System.Manageme nt and WMI.
It's important to note that the free space could be incorrect when
user-quotas are applied.
using System;
using System.Manageme nt;
class Tester {
public static void Main() {
GetFreeSpace(@" \\\\scenic\\kdr ive");
}
public static void GetFreeSpace(st ring ProviderName )
{
// Needs XP or higher
String strSQL = "SELECT FreeSpace, QuotasDisabled ,VolumeName FROM
Win32_LogicalDi sk WHERE providername='" + ProviderName + "'" ;
SelectQuery query = new SelectQuery(str SQL);
ManagementObjec tSearcher searcher = new ManagementObjec tSearcher(query );
foreach (ManagementObje ct mo in searcher.Get()) {
// If both properties are null I suppose there's no CD
if(mo["QuotasDisabled "].ToString() != "true")
Console.WriteLi ne("{0} - Free bytes: {1} ",mo["VolumeName "],
mo["Freespace"]);
else
Console.WriteLi ne("{0} - Free bytes: {1} per-user quota's
applied!!",mo["VolumeName "], mo["Freespace"]);
}
}
}
Willy.
"sam" <an*******@disc ussions.microso ft.com> wrote in message
news:02******** *************** *****@phx.gbl.. .
What is the quickest way to retreive total space and free
space for the network drivers.
Sam