Can I test a floppy drive using WMI & System.Management namespace?
Question
I would find out the floppy inserted state:
- no floppy inserted
- unformatted floppy inserted
- formatted floppy inserted
Can this determined using "WMI" in the System.Management namespace?
If so, can I generate events when the floppy inserted state changes?
Solution 2
Using Bob Kings 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".
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();
}
}
}
OTHER TIPS
This comes from Scripting Center @ MSDN:
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_LogicalDisk Where DeviceID = 'A:'")
For Each objItem in colItems
intFreeSpace = objItem.FreeSpace
If IsNull(intFreeSpace) Then
Wscript.Echo "There is no disk in the floppy drive."
Else
Wscript.Echo "There is a disk in the floppy drive."
End If
Next
You'll also be able to tell if it's formatted or not, by checking other members of the Win32_LogicalDisk class.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow