Can I test a floppy disk using the WMI namespace and System.Management?

I would recognize the inserted floppy state:

  • no floppy card inserted
  • unformatted diskette inserted
  • A formatted floppy card is inserted.

Is it possible to determine the use of WMI in the System.Management namespace?

If so, can I generate events when the state of the inserted floppy changes?

+3
source share
2 answers

Using the idea of ​​Bob Kings, I wrote the following method.

It works great on CDs, removable drives, regular drives.

However, for a floppy disk, it always returns "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();
            }
        }
    }
+1
source

This comes from the 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

, , Win32_LogicalDisk.

+2

Source: https://habr.com/ru/post/1697743/


All Articles