我可以使用 WMI 和 WMI 测试软盘驱动器吗? System.Management 命名空间?

发布于 2024-07-06 14:49:06 字数 184 浏览 5 评论 0原文

我会找出软盘插入状态

  • 没有插入软盘
  • 未格式化软盘已
  • 插入已格式化软盘

这可以在System.Management命名空间中使用“WMI”来确定吗?

如果是这样,当软盘插入状态发生变化时我可以生成事件吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼中杀气 2024-07-13 14:49:06

来自 脚本中心 @ 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 类

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.

小…楫夜泊 2024-07-13 14:49:06

使用鲍勃·金的想法我编写了以下方法。

它在 CD、可移动驱动器、常规驱动器上运行良好。

然而对于软盘它总是返回“不可用”。

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

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();
            }
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文