I am attempting to determine the amount of free space a CD has using the following code:
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_LogicalDisk WHERE DriveType =5");
foreach(ManagementObject mo in searcher.Get())
{
Console.WriteLine( "FreeSpace: "+mo["FreeSpace"].ToString());
Console.WriteLine("CapacitySpace: " + mo["Size"].ToString());
UInt64 usedspace = (UInt64)mo["Size"] - (UInt64)mo["FreeSpace"];
Console.WriteLine("UsedSpace: " + usedspace.ToString());
}
Running the above code, I receive the following output:
FreeSpace: 0
CapacitySpace: 301463552
UsedSpace: 301463552
Ideally, I'd like to report the Windows Explorer statistics - XXX of YYY free. Please note that Windows Explorer is reporting 392 MB free of 702 MB. Thanks!
Update (1 Apr 09): It appears the capability of determining a CD's free space is beyond the WMI and is reliant on the file system of the disk inserted. My testing indicates that Windows will not display capacity information for CDs formatted CDFS; however, it will display capacity information for CDs formatted UDF.
Also, I located an excellent native utility for browsing the WMI referenced here.