我会找出软盘插入状态:
可以使用System.Management命名空间中的“WMI”确定吗?
如果是这样,我可以在软盘插入状态发生变化时生成事件吗?
答案 0 :(得分:2)
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 class的其他成员,您还可以判断它是否已格式化。
答案 1 :(得分:1)
使用Bob Kings的想法我写了以下方法。
它适用于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();
}
}
}