tags:

views:

213

answers:

3

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?

+1  A: 

Also see this related question

Jonas Gulle
+2  A: 

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.

Bob King
Does not work for floppies. See reply for code.
jyoung
+1  A: 

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();
            }
        }
    }
jyoung