利用API函数GetVolumeInformation 取a:\的信息,根据返回值判断是否有软盘存在。
调用disk函数,若返回为真则有软盘,反之无软盘
Option Explicit
Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As _
String, ByVal lpVolumeNameBuffer As _
String, ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, ByVal _
lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As LongFunction disk() As Boolean
Dim Volume As String, SysName As String, drvname As String
Dim SerialNum As Long, SysFlags As Long, ComponentLength As Long, Res As Long
Volume = String(256, 0)
SysName = String(256, 0)
drvname = "a:\"
Res = GetVolumeInformation(drvname, Volume, 255, SerialNum, ComponentLength, SysFlags, SysName, 255)
If Res = 0 Then
disk = False
Else
disk = True
End If
End Function

解决方案 »

  1.   

    向软驱Copy一个文件,捕捉错误信息。
      

  2.   

    不用那么麻烦吧。
    用API  GetDiskFreeSpace 判断。
    如果磁盘总磁道数为0,就是没盘了。
    Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As LongDim i As Long
    i = GetDiskFreeSpace("a:", a, b, c, d)
    If d= 0 Then
    MsgBox "no disk"
    End If
      

  3.   

    可以直接读盘利用err.no来判断