Reputation: 5181
Using an idea from Bob King idea I wrote the following method.
It works great on CD's, removable drives, regular drives.
However for a floppy it always return "Not Available". Any ideas?
public static void TestFloppy( char driveLetter ) {
using( var searcher = new ManagementObjectSearcher( @"SELECT * FROM Win32_LogicalDisk WHERE DeviceID = '" + driveLetter + ":'" ) )
using( var logicalDisks = searcher.Get() ) {
foreach( ManagementObject logicalDisk in logicalDisks ) {
var fs = logicalDisk[ "FreeSpace" ];
Console.WriteLine( "FreeSpace = " + ( fs ?? "Not Available" ) );
logicalDisk.Dispose();
}
}
}
Upvotes: 1
Views: 467
Reputation: 4617
I'm sorry that I don't have a better answer, but I used to do the same thing (use the ManagementObjectSearcher) and found that everytime the code ran the floppy drive would do some sort of seek/init sequence.
So instead I changed to the below and interate:
ManagementClass comp = new ManagementClass(scope, new ManagementPath(obj), null);
comp.Get();
objs = comp.GetInstances();
I want to say this is a known bug in WMI but unfortunately the code comments don't leave any hints :(
Upvotes: 1